[llvm] [SCEVExp] Use Builder.CreateBinOp in InsertBinOp. (PR #154148)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 18 09:24:57 PDT 2025


================
@@ -317,16 +317,16 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
   }
 
   // If we haven't found this binop, insert it.
-  // TODO: Use the Builder, which will make CreateBinOp below fold with
-  // InstSimplifyFolder.
-  Instruction *BO = Builder.Insert(BinaryOperator::Create(Opcode, LHS, RHS));
-  BO->setDebugLoc(Loc);
-  if (Flags & SCEV::FlagNUW)
-    BO->setHasNoUnsignedWrap();
-  if (Flags & SCEV::FlagNSW)
-    BO->setHasNoSignedWrap();
-
-  return BO;
+  Value *Op = Builder.CreateBinOp(Opcode, LHS, RHS);
+  if (auto *BO = dyn_cast<Instruction>(Op)) {
+    BO->setDebugLoc(Loc);
+    if (Flags & SCEV::FlagNUW)
+      BO->setHasNoUnsignedWrap();
+    if (Flags & SCEV::FlagNSW)
+      BO->setHasNoSignedWrap();
----------------
nikic wrote:

As usual, you can't set flags after the fact when using InstSimplifyFolder. They can only be passed to the Create call.

https://github.com/llvm/llvm-project/pull/154148


More information about the llvm-commits mailing list