summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-02-02 06:36:13 +0000
committerChris Lattner <sabre@nondot.org>2006-02-02 06:36:13 +0000
commit49ce35542f9c2944f0eae43dbaa500863c16bd58 (patch)
tree78653ed36147e9f81db4e7638b30bd91ca9b437d
parent166ea0eda7da57316a540ffcae13caba6e1923b5 (diff)
downloadbcm5719-llvm-49ce35542f9c2944f0eae43dbaa500863c16bd58.tar.gz
bcm5719-llvm-49ce35542f9c2944f0eae43dbaa500863c16bd58.zip
add two dag combines:
(C1-X) == C2 --> X == C1-C2 (X+C1) == C2 --> X == C2-C1 This allows us to compile this: bool %X(int %X) { %Y = add int %X, 14 %Z = setne int %Y, 12345 ret bool %Z } into this: _X: cmpl $12331, 4(%esp) setne %al movzbl %al, %eax andl $1, %eax ret not this: _X: movl $14, %eax addl 4(%esp), %eax cmpl $12345, %eax setne %al movzbl %al, %eax andl $1, %eax ret Testcase here: Regression/CodeGen/X86/compare-add.ll nukage of the and coming up next. llvm-svn: 25898
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 6fd1fe4b789..d57400bf4bf 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2623,19 +2623,36 @@ SDOperand DAGCombiner::SimplifySetCC(MVT::ValueType VT, SDOperand N0,
return DAG.getSetCC(VT, N0.getOperand(0), N1.getOperand(1), Cond);
}
}
-
- // Turn (X^C1) == C2 into X == C1^C2 iff X&~C1 = 0. Common for condcodes.
- if (N0.getOpcode() == ISD::XOR)
- if (ConstantSDNode *XORC = dyn_cast<ConstantSDNode>(N0.getOperand(1)))
- if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(N1)) {
+
+ if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(N1)) {
+ if (ConstantSDNode *LHSR = dyn_cast<ConstantSDNode>(N0.getOperand(1))) {
+ // Turn (X+C1) == C2 --> X == C2-C1
+ if (N0.getOpcode() == ISD::ADD && N0.Val->hasOneUse()) {
+ return DAG.getSetCC(VT, N0.getOperand(0),
+ DAG.getConstant(RHSC->getValue()-LHSR->getValue(),
+ N0.getValueType()), Cond);
+ }
+
+ // Turn (X^C1) == C2 into X == C1^C2 iff X&~C1 = 0.
+ if (N0.getOpcode() == ISD::XOR)
// If we know that all of the inverted bits are zero, don't bother
// performing the inversion.
- if (TLI.MaskedValueIsZero(N0.getOperand(0), ~XORC->getValue()))
+ if (TLI.MaskedValueIsZero(N0.getOperand(0), ~LHSR->getValue()))
return DAG.getSetCC(VT, N0.getOperand(0),
- DAG.getConstant(XORC->getValue()^RHSC->getValue(),
+ DAG.getConstant(LHSR->getValue()^RHSC->getValue(),
N0.getValueType()), Cond);
+ }
+
+ // Turn (C1-X) == C2 --> X == C1-C2
+ if (ConstantSDNode *SUBC = dyn_cast<ConstantSDNode>(N0.getOperand(0))) {
+ if (N0.getOpcode() == ISD::SUB && N0.Val->hasOneUse()) {
+ return DAG.getSetCC(VT, N0.getOperand(1),
+ DAG.getConstant(SUBC->getValue()-RHSC->getValue(),
+ N0.getValueType()), Cond);
}
-
+ }
+ }
+
// Simplify (X+Z) == X --> Z == 0
if (N0.getOperand(0) == N1)
return DAG.getSetCC(VT, N0.getOperand(1),
OpenPOWER on IntegriCloud