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

David Green via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 07:40:45 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:

I didn't mean your suggestion was incorrect, just that it was only the fshr by 0 case that was incorrect in the original code (as it turns into a shift by 32-0, which turns into poison). The other cases did not look worth supporting to me as they are more likely to introduce more issues than letting the funnel shift by a constant canonicalize before optimizing it again, but if you want to go that route it sounds OK so long as the other code works with it.

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


More information about the llvm-commits mailing list