[llvm] [InstCombine] Preserve disjoint or after folding casted bitwise logic (PR #136815)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 25 00:18:44 PDT 2025


================
@@ -1869,6 +1869,9 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
 
     // Do the logic op in the intermediate width, then widen more.
     Value *NarrowLogic = Builder.CreateBinOp(LogicOpc, X, Y, I.getName());
+    if (auto *Disjoint = dyn_cast<PossiblyDisjointInst>(&I);
+        Disjoint && Disjoint->isDisjoint())
+      cast<PossiblyDisjointInst>(NarrowLogic)->setIsDisjoint(true);
----------------
nikic wrote:

This may crash in edge cases if CreateBinOp constant folds. You can do one of a) use dyn_cast here b) move the shouldOptimizeCast checks up or c) directly create the or with the right flag (but it looks like we don't have an IRBuilder method for that right nwo).

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


More information about the llvm-commits mailing list