aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2005-08-11 02:18:13 +0000
committerNate Begeman <natebegeman@mac.com>2005-08-11 02:18:13 +0000
commite1fae4a3aeeb1c0f349f9b02a4d6b8fc0a6a9934 (patch)
treef3d8aebe0ed9e114b80ae2cd46099f0c4ccd0d25 /lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parente5d63829fd62d815a330c21ea316e6b4cf943562 (diff)
Add a select_cc optimization for recognizing abs(int). This speeds up an
integer MPEG encoding loop by a factor of two. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22758 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index e331c4a60b..12482efd70 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1495,6 +1495,22 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
return getNode(ISD::AND, AType, Shift, N3);
}
}
+
+ // Check to see if this is an integer abs. select_cc setl[te] X, 0, -X, X ->
+ // Y = sra (X, size(X)-1); xor (add (X, Y), Y)
+ if (N2C && N2C->isNullValue() && (CC == ISD::SETLT || CC == ISD::SETLE) &&
+ N1 == N4 && N3.getOpcode() == ISD::SUB && N1 == N3.getOperand(1)) {
+ if (ConstantSDNode *SubC = dyn_cast<ConstantSDNode>(N3.getOperand(0))) {
+ MVT::ValueType XType = N1.getValueType();
+ if (SubC->isNullValue() && MVT::isInteger(XType)) {
+ SDOperand Shift = getNode(ISD::SRA, XType, N1,
+ getConstant(MVT::getSizeInBits(XType)-1,
+ TLI.getShiftAmountTy()));
+ return getNode(ISD::XOR, XType, getNode(ISD::ADD, XType, N1, Shift),
+ Shift);
+ }
+ }
+ }
}
std::vector<SDOperand> Ops;