@@ -14436,20 +14436,44 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const {
1443614436 }
1443714437 }
1443814438
14439- // Combine (a-2^(M-1)) => sext(trunc(a, M), 64)
14440- if (CC == ISD::SETULT && LHS.getOpcode() == ISD::ADD && OpVT == MVT::i64 &&
14441- isa<ConstantSDNode>(RHS) && isa<ConstantSDNode>(LHS.getOperand(1))) {
14442- uint64_t ShiftVal =
14443- ~(cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue()) + 1;
14444- uint64_t CmpVal = ~(cast<ConstantSDNode>(RHS)->getZExtValue()) + 1;
14445- if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14446- unsigned DestBits = Log2_64(CmpVal);
14447- if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14448- SDValue Conv =
14449- DAG.getSExtOrTrunc(DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14450- MVT::getIntegerVT(DestBits)),
14451- DL, OpVT);
14452- return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14439+ if (CC == ISD::SETULT && isa<ConstantSDNode>(RHS)) {
14440+ uint64_t RHSVal = cast<ConstantSDNode>(RHS)->getZExtValue();
14441+ if (LHS.getOpcode() == ISD::ADD && isa<ConstantSDNode>(LHS.getOperand(1))) {
14442+ uint64_t Addend = cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue();
14443+ if (OpVT == MVT::i64) {
14444+ // (a-2^(M-1)) => sext(trunc(a, M), 64)
14445+ uint64_t ShiftVal = ~Addend + 1;
14446+ uint64_t CmpVal = ~RHSVal + 1;
14447+ if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14448+ unsigned DestBits = Log2_64(CmpVal);
14449+ if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14450+ SDValue Conv = DAG.getSExtOrTrunc(
14451+ DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14452+ MVT::getIntegerVT(DestBits)),
14453+ DL, OpVT);
14454+ return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14455+ }
14456+ }
14457+ } else if (OpVT == MVT::i32) {
14458+ if (RHSVal == 0xffffff00 && Addend == 0xffffff80) {
14459+ SDValue Conv = DAG.getSExtOrTrunc(
14460+ DAG.getSExtOrTrunc(LHS.getOperand(0), DL, MVT::i8), DL, OpVT);
14461+ return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14462+ }
14463+ }
14464+ } else if (LHS.getOpcode() == ISD::SRL &&
14465+ LHS.getOperand(0).getOpcode() == ISD::ADD &&
14466+ isa<ConstantSDNode>(LHS.getOperand(1)) &&
14467+ isa<ConstantSDNode>(LHS.getOperand(0).getOperand(1))) {
14468+ if (RHSVal == 65535 &&
14469+ cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == 16 &&
14470+ cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1))
14471+ ->getZExtValue() == 0xffff8000) {
14472+ SDValue Conv = DAG.getSExtOrTrunc(
14473+ DAG.getSExtOrTrunc(LHS.getOperand(0).getOperand(0), DL, MVT::i16),
14474+ DL, OpVT);
14475+ return DAG.getSetCC(DL, VT, LHS.getOperand(0).getOperand(0), Conv,
14476+ ISD::SETNE);
1445314477 }
1445414478 }
1445514479 }
0 commit comments