[FPEnv] Address post-commit review comment for D71467
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Wed, 15 Jan 2020 14:08:35 +0000 (15:08 +0100)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Wed, 15 Jan 2020 14:10:11 +0000 (15:10 +0100)
Remove a bit of code duplication between CreateFCmp and CreateFCmpS
by creating a shared helper function.

llvm/include/llvm/IR/IRBuilder.h

index a6252b2..6006d74 100644 (file)
@@ -2366,14 +2366,7 @@ public:
   // Note that this differs from CreateFCmpS only if IsFPConstrained is true.
   Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
                     const Twine &Name = "", MDNode *FPMathTag = nullptr) {
-    if (IsFPConstrained)
-      return CreateConstrainedFPCmp(Intrinsic::experimental_constrained_fcmp,
-                                    P, LHS, RHS, Name);
-
-    if (auto *LC = dyn_cast<Constant>(LHS))
-      if (auto *RC = dyn_cast<Constant>(RHS))
-        return Insert(Folder.CreateFCmp(P, LC, RC), Name);
-    return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
+    return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, false);
   }
 
   // Create a signaling floating-point comparison (i.e. one that raises an FP
@@ -2381,9 +2374,19 @@ public:
   // Note that this differs from CreateFCmp only if IsFPConstrained is true.
   Value *CreateFCmpS(CmpInst::Predicate P, Value *LHS, Value *RHS,
                      const Twine &Name = "", MDNode *FPMathTag = nullptr) {
-    if (IsFPConstrained)
-      return CreateConstrainedFPCmp(Intrinsic::experimental_constrained_fcmps,
-                                    P, LHS, RHS, Name);
+    return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, true);
+  }
+
+private:
+  // Helper routine to create either a signaling or a quiet FP comparison.
+  Value *CreateFCmpHelper(CmpInst::Predicate P, Value *LHS, Value *RHS,
+                          const Twine &Name, MDNode *FPMathTag,
+                          bool IsSignaling) {
+    if (IsFPConstrained) {
+      auto ID = IsSignaling ? Intrinsic::experimental_constrained_fcmps
+                            : Intrinsic::experimental_constrained_fcmp;
+      return CreateConstrainedFPCmp(ID, P, LHS, RHS, Name);
+    }
 
     if (auto *LC = dyn_cast<Constant>(LHS))
       if (auto *RC = dyn_cast<Constant>(RHS))
@@ -2391,6 +2394,7 @@ public:
     return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
   }
 
+public:
   CallInst *CreateConstrainedFPCmp(
       Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R,
       const Twine &Name = "",