[llvm] [DAG] Replace getValid*ShiftAmountConstant helpers with getValid*ShiftAmount helpers to support KnownBits analysis (PR #93182)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri May 24 03:27:56 PDT 2024


================
@@ -3020,91 +3020,111 @@ SelectionDAG::getValidShiftAmountConstant(SDValue V,
     // Shifting more than the bitwidth is not valid.
     const APInt &ShAmt = SA->getAPIntValue();
     if (ShAmt.ult(BitWidth))
-      return &ShAmt;
+      return ShAmt.getZExtValue();
+  } else {
+    KnownBits KnownAmt =
+        computeKnownBits(V.getOperand(1), DemandedElts, Depth + 1);
+    if (KnownAmt.isConstant() && KnownAmt.getConstant().ult(BitWidth))
----------------
RKSimon wrote:

The problem we're hitting is that in many cases its not just a bitcast of a constant, its often more complex than that and when trying to use value tracking during legalization we only get one chance, we can't wait for combines to simplify things.

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


More information about the llvm-commits mailing list