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

via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 08:07:30 PDT 2024


================
@@ -3020,91 +3020,113 @@ 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 {
+    // Use computeKnownBits to find a hidden constant (usually type legalized).
+    // e.g. Hidden behind multiple bitcasts/build_vector/casts etc.
+    KnownBits KnownAmt =
+        computeKnownBits(V.getOperand(1), DemandedElts, Depth + 1);
----------------
goldsteinn wrote:

I don't think `Depth + 1` makes sense here. This isn't a recursive function. If its used by a recursive function, the caller should be setting `Depth + 1`.

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


More information about the llvm-commits mailing list