[llvm] LICM: extend hoist BO assoc to mul case (PR #106991)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 05:43:29 PDT 2024


================
@@ -2841,15 +2841,18 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
   auto *Preheader = L.getLoopPreheader();
   assert(Preheader && "Loop is not in simplify form?");
 
-  auto *Inv = BinaryOperator::Create(Opcode, C1, C2, "invariant.op",
-                                     Preheader->getTerminator()->getIterator());
+  IRBuilder<> Builder(Preheader->getTerminator());
+  auto *Inv = Builder.CreateBinOp(Opcode, C1, C2, "invariant.op");
+
   auto *NewBO = BinaryOperator::Create(
       Opcode, LV, Inv, BO->getName() + ".reass", BO->getIterator());
 
   // Copy NUW for ADDs if both instructions have it.
   if (Opcode == Instruction::Add && BO->hasNoUnsignedWrap() &&
       BO0->hasNoUnsignedWrap()) {
-    Inv->setHasNoUnsignedWrap(true);
+    // If the constant-folder didn't kick in, and a new Instruction was created.
----------------
antoniofrighetto wrote:

```suggestion
    // If `Inv` was not constant-folded, a new Instruction has been created.
```

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


More information about the llvm-commits mailing list