Skip to content

Commit 870137d

Browse files
committed
[FPEnv] Address post-commit review comment for D71467
Remove a bit of code duplication between CreateFCmp and CreateFCmpS by creating a shared helper function.
1 parent dc553ce commit 870137d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,31 +2366,35 @@ class IRBuilder : public IRBuilderBase, public Inserter {
23662366
// Note that this differs from CreateFCmpS only if IsFPConstrained is true.
23672367
Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
23682368
const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2369-
if (IsFPConstrained)
2370-
return CreateConstrainedFPCmp(Intrinsic::experimental_constrained_fcmp,
2371-
P, LHS, RHS, Name);
2372-
2373-
if (auto *LC = dyn_cast<Constant>(LHS))
2374-
if (auto *RC = dyn_cast<Constant>(RHS))
2375-
return Insert(Folder.CreateFCmp(P, LC, RC), Name);
2376-
return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
2369+
return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, false);
23772370
}
23782371

23792372
// Create a signaling floating-point comparison (i.e. one that raises an FP
23802373
// exception whenever an input is any NaN, signaling or quiet).
23812374
// Note that this differs from CreateFCmp only if IsFPConstrained is true.
23822375
Value *CreateFCmpS(CmpInst::Predicate P, Value *LHS, Value *RHS,
23832376
const Twine &Name = "", MDNode *FPMathTag = nullptr) {
2384-
if (IsFPConstrained)
2385-
return CreateConstrainedFPCmp(Intrinsic::experimental_constrained_fcmps,
2386-
P, LHS, RHS, Name);
2377+
return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, true);
2378+
}
2379+
2380+
private:
2381+
// Helper routine to create either a signaling or a quiet FP comparison.
2382+
Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
2383+
const Twine &Name, MDNode *FPMathTag,
2384+
bool IsSignaling) {
2385+
if (IsFPConstrained) {
2386+
auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
2387+
: Intrinsic::experimental_constrained_fcmp;
2388+
return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
2389+
}
23872390

23882391
if (auto *LC = dyn_cast<Constant>(LHS))
23892392
if (auto *RC = dyn_cast<Constant>(RHS))
23902393
return Insert(Folder.CreateFCmp(P, LC, RC), Name);
23912394
return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
23922395
}
23932396

2397+
public:
23942398
CallInst *CreateConstrainedFPCmp(
23952399
Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R,
23962400
const Twine &Name = "",

0 commit comments

Comments
 (0)