[llvm] [SelectionDAG] Fix incorrect fold condition in foldSetCCWithFunnelShift. (PR #137637)

via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 05:00:21 PDT 2025


================
@@ -4462,7 +4462,8 @@ static SDValue foldSetCCWithFunnelShift(EVT VT, SDValue N0, SDValue N1,
 
   unsigned BitWidth = N0.getScalarValueSizeInBits();
   auto *ShAmtC = isConstOrConstSplat(N0.getOperand(2));
-  if (!ShAmtC || ShAmtC->getAPIntValue().uge(BitWidth))
+  APInt AmtVal = ShAmtC->getAPIntValue();
+  if (!ShAmtC || AmtVal.uge(BitWidth) || AmtVal.isZero())
----------------
Ruhung wrote:

> A more precise way to implement this check would be to first reduce the shift amount modulo the bitwidth:
> 
> ```
>   unsigned ShAmt = ShAmtC->getAPIntValue().urem(BitWidth).getZExtValue();
> ```
> 
> and then bail out if it is zero.

The shift amount needs to be less than BitWidth, so a modulo operation may not be necessary?

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


More information about the llvm-commits mailing list