[llvm] [SelectionDAG] Improve isOrEquivalentToAdd (PR #82767)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 09:27:41 PST 2024


================
@@ -4214,7 +4214,7 @@ bool SelectionDAGISel::isOrEquivalentToAdd(const SDNode *N) const {
     // the alignment, then this or is really an add.
     return (Off >= 0) && (((A.value() - 1) & Off) == unsigned(Off));
   }
-  return false;
+  return CurDAG->haveNoCommonBitsSet(N->getOperand(0), N->getOperand(1));
----------------
topperc wrote:

I'd currently recommend checking both hasDisjoint and haveNoCommonbitsSet. SelectionDAG does not have any code to set hasDisjoint so it will only get set if it was set in IR.

There seems to be some duplication in functions we have for this in SelectionDAG. I think another option is to replace
```
def AddLike: PatFrags<(ops node:$A, node:$B),                                    
                      [(add node:$A, node:$B), (or node:$A, node:$B)], [{        
    return N->getOpcode() == ISD::ADD || isOrEquivalentToAdd(N);                 
}]>;
```

with
```
def AddLike: PatFrags<(ops node:$A, node:$B),                                    
                      [(add node:$A, node:$B), (or node:$A, node:$B)], [{        
    return CurDAG->isBaseWithConstantOffset(SDValue(N, 0));
}]>;
```

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


More information about the llvm-commits mailing list