[llvm] [DAGCombine] Remove OneUse restriction when folding (shl (add x, c1), c2) and (shl (sext (add x, c1)), c2) (PR #101294)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 10 23:25:09 PDT 2024
================
@@ -59541,3 +59541,18 @@ Align X86TargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
return Align(1ULL << ExperimentalPrefInnermostLoopAlignment);
return TargetLowering::getPrefLoopAlignment();
}
+
+bool X86TargetLowering::isDesirableToCommuteWithShift(
+ const SDNode *N, CombineLevel Level) const {
+ assert((N->getOpcode() == ISD::SHL || N->getOpcode() == ISD::SRA ||
+ N->getOpcode() == ISD::SRL) &&
+ "Expected shift op");
+
+ SDValue ShiftLHS = N->getOperand(0);
+ if ((ShiftLHS.getOpcode() == ISD::SIGN_EXTEND &&
+ !(ShiftLHS->hasOneUse() && ShiftLHS.getOperand(0)->hasOneUse())) ||
+ !ShiftLHS->hasOneUse())
+ return false;
----------------
goldsteinn wrote:
Here (and everywhere else) think it would be much cleaner to just do:
```
match ShiftLHS->hasOneUse() || match(ShiftLHS, m_SExtLike(m_OneUse(m_Value(X)))
```
NB: The `m_SExtLike` needs to be added to `SDPatternMatch.h`, its just `ZEXT` + `NNEG`.
https://github.com/llvm/llvm-project/pull/101294
More information about the llvm-commits
mailing list