@@ -16726,10 +16726,6 @@ combineVectorSizedSetCCEquality(EVT VT, SDValue X, SDValue Y, ISD::CondCode CC,
16726
16726
DAG.getConstant(0, DL, XLenVT), CC);
16727
16727
}
16728
16728
16729
- // Replace (seteq (i64 (and X, 0xffffffff)), C1) with
16730
- // (seteq (i64 (sext_inreg (X, i32)), C1')) where C1' is C1 sign extended from
16731
- // bit 31. Same for setne. C1' may be cheaper to materialize and the sext_inreg
16732
- // can become a sext.w instead of a shift pair.
16733
16729
static SDValue performSETCCCombine(SDNode *N,
16734
16730
TargetLowering::DAGCombinerInfo &DCI,
16735
16731
const RISCVSubtarget &Subtarget) {
@@ -16749,20 +16745,36 @@ static SDValue performSETCCCombine(SDNode *N,
16749
16745
combineVectorSizedSetCCEquality(VT, N0, N1, Cond, dl, DAG, Subtarget))
16750
16746
return V;
16751
16747
16752
- // (X & -4096) == 0 -> (X >> 12) == 0 if the AND constant can't use ANDI.
16753
16748
if (DCI.isAfterLegalizeDAG() && isNullConstant(N1) &&
16754
16749
N0.getOpcode() == ISD::AND && N0.hasOneUse() &&
16755
16750
isa<ConstantSDNode>(N0.getOperand(1))) {
16756
16751
const APInt &AndRHSC =
16757
16752
cast<ConstantSDNode>(N0.getOperand(1))->getAPIntValue();
16753
+ // (X & -(1 << C)) == 0 -> (X >> C) == 0 if the AND constant can't use ANDI.
16758
16754
if (!isInt<12>(AndRHSC.getSExtValue()) && AndRHSC.isNegatedPowerOf2()) {
16759
16755
unsigned ShiftBits = AndRHSC.countr_zero();
16760
- SDValue Shift = DAG.getNode(ISD::SRL, dl, VT, N0.getOperand(0),
16761
- DAG.getConstant(ShiftBits, dl, VT));
16756
+ SDValue Shift = DAG.getNode(ISD::SRL, dl, OpVT, N0.getOperand(0),
16757
+ DAG.getConstant(ShiftBits, dl, OpVT));
16758
+ return DAG.getSetCC(dl, VT, Shift, N1, Cond);
16759
+ }
16760
+
16761
+ // Similar to above but handling the lower 32 bits by using srliw.
16762
+ // FIXME: Handle the case where N1 is non-zero.
16763
+ if (OpVT == MVT::i64 && AndRHSC.getZExtValue() <= 0xffffffff &&
16764
+ isPowerOf2_32(-uint32_t(AndRHSC.getZExtValue()))) {
16765
+ unsigned ShiftBits = llvm::countr_zero(AndRHSC.getZExtValue());
16766
+ SDValue And = DAG.getNode(ISD::AND, dl, OpVT, N0.getOperand(0),
16767
+ DAG.getConstant(0xffffffff, dl, OpVT));
16768
+ SDValue Shift = DAG.getNode(ISD::SRL, dl, OpVT, And,
16769
+ DAG.getConstant(ShiftBits, dl, OpVT));
16762
16770
return DAG.getSetCC(dl, VT, Shift, N1, Cond);
16763
16771
}
16764
16772
}
16765
16773
16774
+ // Replace (seteq (i64 (and X, 0xffffffff)), C1) with
16775
+ // (seteq (i64 (sext_inreg (X, i32)), C1')) where C1' is C1 sign extended from
16776
+ // bit 31. Same for setne. C1' may be cheaper to materialize and the
16777
+ // sext_inreg can become a sext.w instead of a shift pair.
16766
16778
if (OpVT != MVT::i64 || !Subtarget.is64Bit())
16767
16779
return SDValue();
16768
16780
0 commit comments