summaryrefslogtreecommitdiff
path: root/lib/Target/SystemZ
diff options
context:
space:
mode:
authorRichard Sandiford <rsandifo@linux.vnet.ibm.com>2013-12-13 15:50:30 +0000
committerRichard Sandiford <rsandifo@linux.vnet.ibm.com>2013-12-13 15:50:30 +0000
commit584940e3c65aca9e8329cae7b3ffda8ea51da81d (patch)
treef141feacb23e1c3a331b58c72b1b42472c194daa /lib/Target/SystemZ
parent5f65b24e4df944e0dbab75aa4ee7efd12a1f820e (diff)
downloadllvm-584940e3c65aca9e8329cae7b3ffda8ea51da81d.tar.gz
llvm-584940e3c65aca9e8329cae7b3ffda8ea51da81d.tar.bz2
llvm-584940e3c65aca9e8329cae7b3ffda8ea51da81d.tar.xz
[SystemZ] Optimize X [!=]= Y in cases where X - Y or Y - X is also computed
In those cases it's better to compare the result of the subtraction against zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197239 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SystemZ')
-rw-r--r--lib/Target/SystemZ/SystemZISelLowering.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Target/SystemZ/SystemZISelLowering.cpp b/lib/Target/SystemZ/SystemZISelLowering.cpp
index 6c443b59f7..baef2c1d0b 100644
--- a/lib/Target/SystemZ/SystemZISelLowering.cpp
+++ b/lib/Target/SystemZ/SystemZISelLowering.cpp
@@ -1271,6 +1271,26 @@ static unsigned reverseCCMask(unsigned CCMask) {
(CCMask & SystemZ::CCMASK_CMP_UO));
}
+// Check whether C tests for equality between X and Y and whether X - Y
+// or Y - X is also computed. In that case it's better to compare the
+// result of the subtraction against zero.
+static void adjustForSubtraction(SelectionDAG &DAG, Comparison &C) {
+ if (C.CCMask == SystemZ::CCMASK_CMP_EQ ||
+ C.CCMask == SystemZ::CCMASK_CMP_NE) {
+ for (SDNode::use_iterator I = C.Op0->use_begin(), E = C.Op0->use_end();
+ I != E; ++I) {
+ SDNode *N = *I;
+ if (N->getOpcode() == ISD::SUB &&
+ ((N->getOperand(0) == C.Op0 && N->getOperand(1) == C.Op1) ||
+ (N->getOperand(0) == C.Op1 && N->getOperand(1) == C.Op0))) {
+ C.Op0 = SDValue(N, 0);
+ C.Op1 = DAG.getConstant(0, N->getValueType(0));
+ return;
+ }
+ }
+ }
+}
+
// Check whether C compares a floating-point value with zero and if that
// floating-point value is also negated. In this case we can use the
// negation to set CC, so avoiding separate LOAD AND TEST and
@@ -1540,6 +1560,7 @@ static Comparison getCmp(SelectionDAG &DAG, SDValue CmpOp0, SDValue CmpOp1,
C.CCMask &= ~SystemZ::CCMASK_CMP_UO;
adjustZeroCmp(DAG, C);
adjustSubwordCmp(DAG, C);
+ adjustForSubtraction(DAG, C);
}
if (shouldSwapCmpOperands(C)) {