@@ -14407,15 +14407,18 @@ SDValue PPCTargetLowering::DAGCombineExtBoolTrunc(SDNode *N,
1440714407 ShiftCst);
1440814408}
1440914409
14410- SDValue PPCTargetLowering::combineSetCC(SDNode *N,
14411- DAGCombinerInfo &DCI) const {
14412- assert(N->getOpcode() == ISD::SETCC &&
14413- "Should be called with a SETCC node");
14410+ SDValue PPCTargetLowering::combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const {
14411+ assert(N->getOpcode() == ISD::SETCC && "Should be called with a SETCC node");
1441414412
1441514413 ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
14414+ SDValue LHS = N->getOperand(0);
14415+ SDValue RHS = N->getOperand(1);
14416+ SDLoc DL(N);
14417+ SelectionDAG &DAG = DCI.DAG;
14418+ EVT VT = N->getValueType(0);
14419+ EVT OpVT = LHS.getValueType();
14420+
1441614421 if (CC == ISD::SETNE || CC == ISD::SETEQ) {
14417- SDValue LHS = N->getOperand(0);
14418- SDValue RHS = N->getOperand(1);
1441914422
1442014423 // If there is a '0 - y' pattern, canonicalize the pattern to the RHS.
1442114424 if (LHS.getOpcode() == ISD::SUB && isNullConstant(LHS.getOperand(0)) &&
@@ -14426,15 +14429,29 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N,
1442614429 // x != 0-y --> x+y != 0
1442714430 if (RHS.getOpcode() == ISD::SUB && isNullConstant(RHS.getOperand(0)) &&
1442814431 RHS.hasOneUse()) {
14429- SDLoc DL(N);
14430- SelectionDAG &DAG = DCI.DAG;
14431- EVT VT = N->getValueType(0);
14432- EVT OpVT = LHS.getValueType();
1443314432 SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LHS, RHS.getOperand(1));
1443414433 return DAG.getSetCC(DL, VT, Add, DAG.getConstant(0, DL, OpVT), CC);
1443514434 }
1443614435 }
1443714436
14437+ // Combine (a-2^(M-1)) => sext(trunc(a, M), 64)
14438+ if (CC == ISD::SETULT && LHS.getOpcode() == ISD::ADD && OpVT == MVT::i64 &&
14439+ isa<ConstantSDNode>(RHS) && isa<ConstantSDNode>(LHS.getOperand(1))) {
14440+ uint64_t ShiftVal =
14441+ ~(cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue()) + 1;
14442+ uint64_t CmpVal = ~(cast<ConstantSDNode>(RHS)->getZExtValue()) + 1;
14443+ if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {
14444+ unsigned DestBits = Log2_64(CmpVal);
14445+ if (DestBits == 8 || DestBits == 16 || DestBits == 32) {
14446+ SDValue Conv =
14447+ DAG.getSExtOrTrunc(DAG.getSExtOrTrunc(LHS.getOperand(0), DL,
14448+ MVT::getIntegerVT(DestBits)),
14449+ DL, OpVT);
14450+ return DAG.getSetCC(DL, VT, LHS.getOperand(0), Conv, ISD::SETNE);
14451+ }
14452+ }
14453+ }
14454+
1443814455 return DAGCombineTruncBoolExt(N, DCI);
1443914456}
1444014457
0 commit comments