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