@@ -14554,44 +14554,43 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const {
1455414554 }
1455514555 }
1455614556
14557- if (CC == ISD::SETULT && isa<ConstantSDNode>(RHS)) {
14558- uint64_t RHSVal = cast<ConstantSDNode>(RHS)->getZExtValue();
14559- if (LHS.getOpcode() == ISD::ADD && isa<ConstantSDNode>(LHS.getOperand(1))) {
14560- uint64_t Addend = cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue();
14561- if (OpVT == MVT::i64) {
14562- uint64_t ShiftVal = ~Addend + 1;
14563- uint64_t CmpVal = ~RHSVal + 1;
14564- if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14565- unsigned DestBits = Log2_64(CmpVal);
14566- if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14567- SDValue Conv = DAG.getSExtOrTrunc(
14568- DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14569- MVT::getIntegerVT(DestBits)),
14570- DL, OpVT);
14571- return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14572- }
14573- }
14574- } else if (OpVT == MVT::i32) {
14575- if (RHSVal == 0xffffff00 && Addend == 0xffffff80) {
14576- SDValue Conv = DAG.getSExtOrTrunc(
14577- DAG.getSExtOrTrunc(LHS.getOperand(0), DL, MVT::i8), DL, OpVT);
14578- return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14579- }
14557+ if (CC == ISD::SETULT) {
14558+ auto GetTruncExtCmp = [&](SDValue Src, EVT DstVT) {
14559+ return DAG.getSetCC(
14560+ DL, VT, Src,
14561+ DAG.getSExtOrTrunc(DAG.getSExtOrTrunc(Src, DL, DstVT), DL, OpVT),
14562+ ISD::SETNE);
14563+ };
14564+ // ult (add x -0x80000000) -0x100000000 -> ne x (sext:i64 (trunc:i32 x))
14565+ // ult (add x -0x8000) -0x10000 -> ne x (sext:i64 (trunc:i16 x))
14566+ // ult (add x -0x80) -0x100 -> ne x (sext:i64 (trunc:i8 x))
14567+ // ult (add x -0x80) -0x100 -> ne x (sext:i32 (trunc:i16 x))
14568+ // ult (add x -0x80) -0x100 -> ne x (sext:i16 (trunc:i8 x))
14569+ if (LHS.getOpcode() == ISD::ADD) {
14570+ const auto *Addend = dyn_cast<ConstantSDNode>(LHS.getOperand(1));
14571+ const auto *RhsC = dyn_cast<ConstantSDNode>(RHS);
14572+ if (Addend && RhsC) {
14573+ int64_t AddendVal = Addend->getSExtValue();
14574+ int64_t RhsVal = RhsC->getSExtValue();
14575+ if (AddendVal == -0x80000000L && RhsVal == -0x100000000L &&
14576+ OpVT == MVT::i64)
14577+ return GetTruncExtCmp(LHS.getOperand(0), MVT::i32);
14578+ if (AddendVal == -0x8000 && RhsVal == -0x10000 && OpVT == MVT::i64)
14579+ return GetTruncExtCmp(LHS.getOperand(0), MVT::i16);
14580+ if (AddendVal == -0x80 && RhsVal == -0x100 &&
14581+ (OpVT == MVT::i64 || OpVT == MVT::i32 || OpVT == MVT::i16))
14582+ return GetTruncExtCmp(LHS.getOperand(0), MVT::i8);
1458014583 }
14584+ // ult (srl (add x -0x8000) 16) 0xffff -> ne x (sext:i32 (trunc:i16 x))
1458114585 } else if (LHS.getOpcode() == ISD::SRL &&
14582- LHS.getOperand(0).getOpcode() == ISD::ADD &&
14583- isa<ConstantSDNode>(LHS.getOperand(1)) &&
14584- isa<ConstantSDNode>(LHS.getOperand(0).getOperand(1))) {
14585- if (RHSVal == 0xffff &&
14586- cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == 16 &&
14587- cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1))
14588- ->getZExtValue() == 0xffff8000) {
14589- SDValue Conv = DAG.getSExtOrTrunc(
14590- DAG.getSExtOrTrunc(LHS.getOperand(0).getOperand(0), DL, MVT::i16),
14591- DL, OpVT);
14592- return DAG.getSetCC(DL, VT, LHS.getOperand(0).getOperand(0), Conv,
14593- ISD::SETNE);
14594- }
14586+ LHS.getOperand(0).getOpcode() == ISD::ADD) {
14587+ const auto *SrlAmt = dyn_cast<ConstantSDNode>(LHS.getOperand(1));
14588+ const auto *Addend =
14589+ dyn_cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1));
14590+ const auto *RhsC = dyn_cast<ConstantSDNode>(RHS);
14591+ if (SrlAmt && Addend && RhsC && SrlAmt->getSExtValue() == 16 &&
14592+ Addend->getSExtValue() == -0x8000 && RhsC->getSExtValue() == 0xffff)
14593+ return GetTruncExtCmp(LHS.getOperand(0).getOperand(0), MVT::i8);
1459514594 }
1459614595 }
1459714596
0 commit comments