@@ -16726,10 +16726,6 @@ combineVectorSizedSetCCEquality(EVT VT, SDValue X, SDValue Y, ISD::CondCode CC,
1672616726 DAG.getConstant(0, DL, XLenVT), CC);
1672716727}
1672816728
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.
1673316729static SDValue performSETCCCombine(SDNode *N,
1673416730 TargetLowering::DAGCombinerInfo &DCI,
1673516731 const RISCVSubtarget &Subtarget) {
@@ -16749,20 +16745,36 @@ static SDValue performSETCCCombine(SDNode *N,
1674916745 combineVectorSizedSetCCEquality(VT, N0, N1, Cond, dl, DAG, Subtarget))
1675016746 return V;
1675116747
16752- // (X & -4096) == 0 -> (X >> 12) == 0 if the AND constant can't use ANDI.
1675316748 if (DCI.isAfterLegalizeDAG() && isNullConstant(N1) &&
1675416749 N0.getOpcode() == ISD::AND && N0.hasOneUse() &&
1675516750 isa<ConstantSDNode>(N0.getOperand(1))) {
1675616751 const APInt &AndRHSC =
1675716752 cast<ConstantSDNode>(N0.getOperand(1))->getAPIntValue();
16753+ // (X & -(1 << C)) == 0 -> (X >> C) == 0 if the AND constant can't use ANDI.
1675816754 if (!isInt<12>(AndRHSC.getSExtValue()) && AndRHSC.isNegatedPowerOf2()) {
1675916755 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));
1676216770 return DAG.getSetCC(dl, VT, Shift, N1, Cond);
1676316771 }
1676416772 }
1676516773
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.
1676616778 if (OpVT != MVT::i64 || !Subtarget.is64Bit())
1676716779 return SDValue();
1676816780
0 commit comments