[llvm] [VectorCombine] Use InstSimplifyFolder to simplify instrs on creation. (PR #146350)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 11:03:22 PDT 2025


================
@@ -1459,10 +1461,12 @@ bool VectorCombine::foldBinopOfReductions(Instruction &I) {
   LLVM_DEBUG(dbgs() << "Found two mergeable reductions: " << I
                     << "\n  OldCost: " << OldCost << " vs NewCost: " << NewCost
                     << "\n");
-  Value *VectorBO = Builder.CreateBinOp(BinOpOpc, V0, V1);
-  if (auto *PDInst = dyn_cast<PossiblyDisjointInst>(&I))
-    if (auto *PDVectorBO = dyn_cast<PossiblyDisjointInst>(VectorBO))
-      PDVectorBO->setIsDisjoint(PDInst->isDisjoint());
+  Value *VectorBO;
+  if (BinOpOpc == Instruction::Or)
+    VectorBO = Builder.CreateOr(V0, V1, "",
+                                cast<PossiblyDisjointInst>(I).isDisjoint());
+  else
+    VectorBO = Builder.CreateBinOp(BinOpOpc, V0, V1);
----------------
fhahn wrote:

Yeah I added `CreateBinOpDisjoint` (similar to CreateBinOpFMF). ALthough there I still retained the `if`, because we need to call isDisjoint as well.

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


More information about the llvm-commits mailing list