[llvm] [DAGCombine] Remove oneuse restrictions for RISCV in folding (shl (add_nsw x, c1)), c2) and folding (shl(sext(add x, c1)), c2) in some scenarios (PR #101294)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 01:11:04 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;
----------------
RKSimon wrote:

why not just add a local `using namespace llvm::SDPatternMatch` - we already do this in X86ISelLowering.cpp in several places (we get namespace clashes if we do it across the entire file).

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


More information about the llvm-commits mailing list