[llvm] [Reassociate] Use disjoint flag to convert Or to Add. (PR #72772)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 14:43:47 PST 2023


================
@@ -2252,9 +2252,10 @@ void ReassociatePass::OptimizeInst(Instruction *I) {
   // with no common bits set, convert it to X+Y.
   if (I->getOpcode() == Instruction::Or &&
       shouldConvertOrWithNoCommonBitsToAdd(I) && !isLoadCombineCandidate(I) &&
-      haveNoCommonBitsSet(I->getOperand(0), I->getOperand(1),
-                          SimplifyQuery(I->getModule()->getDataLayout(),
-                                        /*DT=*/nullptr, /*AC=*/nullptr, I))) {
+      (I->isDisjoint() ||
+       haveNoCommonBitsSet(I->getOperand(0), I->getOperand(1),
+                           SimplifyQuery(I->getModule()->getDataLayout(),
+                                         /*DT=*/nullptr, /*AC=*/nullptr, I)))) {
----------------
topperc wrote:

I looked at this some more. When we reassociate a set of Ors we lose the flag, but then we revisit them to try more reassociation that may want to treat them as Adds. But we've lost the flag. So I think we need to call haveNoCommonBitsSet again somewhere to recover it.

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


More information about the llvm-commits mailing list