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

David Green via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 12:07:49 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())
----------------
davemgreen wrote:

A funnel shift will rotate around (so can be > bitwidth), a shift will produce poison if the shift amount is >= bitwidth. It looks like it might only be fshr that is incorrect, not fshl? We should have canonicalized the constant shift amount so it is probably OK either way so long as we fix the bug in non-canonical forms.

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


More information about the llvm-commits mailing list