Skip to content

Commit 7efafb0

Browse files
committed
[IRBuilder] Migrate fcmp to folding API
This was one of the last leftovers still using a Create-style instead of Fold-style API. Convert FoldICmp into FoldCmp so it can handle both icmp and fcmp.
1 parent 1e86e92 commit 7efafb0

File tree

7 files changed

+10
-54
lines changed

7 files changed

+10
-54
lines changed

llvm/include/llvm/Analysis/InstSimplifyFolder.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class InstSimplifyFolder final : public IRBuilderFolder {
7272
return simplifyUnOp(Opc, V, FMF, SQ);
7373
}
7474

75-
Value *FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
76-
return simplifyICmpInst(P, LHS, RHS, SQ);
75+
Value *FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
76+
return simplifyCmpInst(P, LHS, RHS, SQ);
7777
}
7878

7979
Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
@@ -139,15 +139,6 @@ class InstSimplifyFolder final : public IRBuilderFolder {
139139
return C; // avoid calling Fold
140140
return ConstFolder.CreatePointerBitCastOrAddrSpaceCast(C, DestTy);
141141
}
142-
143-
//===--------------------------------------------------------------------===//
144-
// Compare Instructions
145-
//===--------------------------------------------------------------------===//
146-
147-
Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
148-
Constant *RHS) const override {
149-
return ConstFolder.CreateFCmp(P, LHS, RHS);
150-
}
151142
};
152143

153144
} // end namespace llvm

llvm/include/llvm/Analysis/TargetFolder.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TargetFolder final : public IRBuilderFolder {
9999
return FoldBinOp(Opc, LHS, RHS);
100100
}
101101

102-
Value *FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
102+
Value *FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
103103
auto *LC = dyn_cast<Constant>(LHS);
104104
auto *RC = dyn_cast<Constant>(RHS);
105105
if (LC && RC)
@@ -216,15 +216,6 @@ class TargetFolder final : public IRBuilderFolder {
216216
return C; // avoid calling Fold
217217
return Fold(ConstantExpr::getPointerBitCastOrAddrSpaceCast(C, DestTy));
218218
}
219-
220-
//===--------------------------------------------------------------------===//
221-
// Compare Instructions
222-
//===--------------------------------------------------------------------===//
223-
224-
Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
225-
Constant *RHS) const override {
226-
return Fold(ConstantExpr::getCompare(P, LHS, RHS));
227-
}
228219
};
229220

230221
}

llvm/include/llvm/IR/ConstantFolder.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ConstantFolder final : public IRBuilderFolder {
9595
return nullptr;
9696
}
9797

98-
Value *FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
98+
Value *FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
9999
auto *LC = dyn_cast<Constant>(LHS);
100100
auto *RC = dyn_cast<Constant>(RHS);
101101
if (LC && RC)
@@ -201,15 +201,6 @@ class ConstantFolder final : public IRBuilderFolder {
201201
Type *DestTy) const override {
202202
return ConstantExpr::getPointerBitCastOrAddrSpaceCast(C, DestTy);
203203
}
204-
205-
//===--------------------------------------------------------------------===//
206-
// Compare Instructions
207-
//===--------------------------------------------------------------------===//
208-
209-
Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
210-
Constant *RHS) const override {
211-
return ConstantExpr::getCompare(P, LHS, RHS);
212-
}
213204
};
214205

215206
} // end namespace llvm

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,7 @@ class IRBuilderBase {
23502350

23512351
Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
23522352
const Twine &Name = "") {
2353-
if (auto *V = Folder.FoldICmp(P, LHS, RHS))
2353+
if (auto *V = Folder.FoldCmp(P, LHS, RHS))
23542354
return V;
23552355
return Insert(new ICmpInst(P, LHS, RHS), Name);
23562356
}

llvm/include/llvm/IR/IRBuilderFolder.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class IRBuilderFolder {
4848
virtual Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
4949
FastMathFlags FMF) const = 0;
5050

51-
virtual Value *FoldICmp(CmpInst::Predicate P, Value *LHS,
52-
Value *RHS) const = 0;
51+
virtual Value *FoldCmp(CmpInst::Predicate P, Value *LHS,
52+
Value *RHS) const = 0;
5353

5454
virtual Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
5555
bool IsInBounds = false) const = 0;
@@ -84,13 +84,6 @@ class IRBuilderFolder {
8484
virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
8585
virtual Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C,
8686
Type *DestTy) const = 0;
87-
88-
//===--------------------------------------------------------------------===//
89-
// Compare Instructions
90-
//===--------------------------------------------------------------------===//
91-
92-
virtual Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
93-
Constant *RHS) const = 0;
9487
};
9588

9689
} // end namespace llvm

llvm/include/llvm/IR/NoFolder.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class NoFolder final : public IRBuilderFolder {
7070
return nullptr;
7171
}
7272

73-
Value *FoldICmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
73+
Value *FoldCmp(CmpInst::Predicate P, Value *LHS, Value *RHS) const override {
7474
return nullptr;
7575
}
7676

@@ -129,15 +129,6 @@ class NoFolder final : public IRBuilderFolder {
129129
Constant *C, Type *DestTy) const override {
130130
return CastInst::CreatePointerBitCastOrAddrSpaceCast(C, DestTy);
131131
}
132-
133-
//===--------------------------------------------------------------------===//
134-
// Compare Instructions
135-
//===--------------------------------------------------------------------===//
136-
137-
Instruction *CreateFCmp(CmpInst::Predicate P,
138-
Constant *LHS, Constant *RHS) const override {
139-
return new FCmpInst(P, LHS, RHS);
140-
}
141132
};
142133

143134
} // end namespace llvm

llvm/lib/IR/IRBuilder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,9 +1053,8 @@ Value *IRBuilderBase::CreateFCmpHelper(
10531053
return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
10541054
}
10551055

1056-
if (auto *LC = dyn_cast<Constant>(LHS))
1057-
if (auto *RC = dyn_cast<Constant>(RHS))
1058-
return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1056+
if (auto *V = Folder.FoldCmp(P, LHS, RHS))
1057+
return V;
10591058
return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
10601059
}
10611060

0 commit comments

Comments
 (0)