diff options
author | Li Jia He <hljhehlj@cn.ibm.com> | 2018-10-26 06:48:53 +0000 |
---|---|---|
committer | Li Jia He <hljhehlj@cn.ibm.com> | 2018-10-26 06:48:53 +0000 |
commit | f6fb752fe80f05e57b4b6928597d1113a558a7c1 (patch) | |
tree | eb420d91f41670cabc3f3ad5e53915d90e81ccc9 /llvm/lib/Target/PowerPC/PPCISelLowering.cpp | |
parent | 95214673181458834976505992216a30465f3b9a (diff) | |
download | bcm5719-llvm-f6fb752fe80f05e57b4b6928597d1113a558a7c1.tar.gz bcm5719-llvm-f6fb752fe80f05e57b4b6928597d1113a558a7c1.zip |
[PowerPC] Fix some missed optimization opportunities in combineSetCC
For both operands are bool, short, int, long, long long, add the following optimization.
1. 0-x == y --> x+y ==0
2. 0-x != y --> x+y != 0
Review: nemanjai
Differential Revision: https://reviews.llvm.org/D53360
llvm-svn: 345366
Diffstat (limited to 'llvm/lib/Target/PowerPC/PPCISelLowering.cpp')
-rw-r--r-- | llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp index 860181c57bd..a135667beaa 100644 --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -11823,6 +11823,37 @@ SDValue PPCTargetLowering::DAGCombineExtBoolTrunc(SDNode *N, ShiftCst); } +SDValue PPCTargetLowering::combineSetCC(SDNode *N, + DAGCombinerInfo &DCI) const { + assert(N->getOpcode() == ISD::SETCC && + "Should be called with a SETCC node"); + + ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get(); + if (CC == ISD::SETNE || CC == ISD::SETEQ) { + SDValue LHS = N->getOperand(0); + SDValue RHS = N->getOperand(1); + + // If there is a '0 - y' pattern, canonicalize the pattern to the RHS. + if (LHS.getOpcode() == ISD::SUB && isNullConstant(LHS.getOperand(0)) && + LHS.hasOneUse()) + std::swap(LHS, RHS); + + // x == 0-y --> x+y == 0 + // x != 0-y --> x+y != 0 + if (RHS.getOpcode() == ISD::SUB && isNullConstant(RHS.getOperand(0)) && + RHS.hasOneUse()) { + SDLoc DL(N); + SelectionDAG &DAG = DCI.DAG; + EVT VT = N->getValueType(0); + EVT OpVT = LHS.getValueType(); + SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LHS, RHS.getOperand(1)); + return DAG.getSetCC(DL, VT, Add, DAG.getConstant(0, DL, OpVT), CC); + } + } + + return DAGCombineTruncBoolExt(N, DCI); +} + // Is this an extending load from an f32 to an f64? static bool isFPExtLoad(SDValue Op) { if (LoadSDNode *LD = dyn_cast<LoadSDNode>(Op.getNode())) @@ -12554,6 +12585,9 @@ SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N, case ISD::TRUNCATE: return combineTRUNCATE(N, DCI); case ISD::SETCC: + if (SDValue CSCC = combineSetCC(N, DCI)) + return CSCC; + LLVM_FALLTHROUGH; case ISD::SELECT_CC: return DAGCombineTruncBoolExt(N, DCI); case ISD::SINT_TO_FP: |