[llvm] [SelectionDAG] Fold (icmp eq/ne (shift X, C), 0) -> (icmp eq/ne X, 0) (PR #88801)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 07:15:08 PDT 2024
================
@@ -4516,6 +4516,27 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
}
}
}
+
+ // Optimize
+ // (icmp eq/ne (shift N00, N01C), 0) -> (icmp eq/ne N00, 0)
+ // If shift is logical and all shifted out bits are known to be zero, then
+ // the zero'd ness doesnt change and we can omit the shift.
+ // If all shifted out bits are equal to at least one bit that isn't
+ // shifted out, then the zero'd ness doesnt change and we can omit the
+ // shift.
+ if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) && C1.isZero() &&
+ N0.hasOneUse() &&
+ (N0.getOpcode() == ISD::SHL || N0.getOpcode() == ISD::SRL)) {
+ if (ConstantSDNode *ShAmt = isConstOrConstSplat(N0.getOperand(1))) {
----------------
RKSimon wrote:
Could we use getValidMaximumShiftAmountConstant here instead?
https://github.com/llvm/llvm-project/pull/88801
More information about the llvm-commits
mailing list