aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-07-01 02:58:21 +0000
committerDan Gohman <gohman@apple.com>2010-07-01 02:58:21 +0000
commitabd1d859b3c35957a3dd5965cf1fd420df0d20e3 (patch)
tree1c5eae4645579e2006beff60d02b4d89351db6cc
parent79b634c244e178ff4ab38151c77d2307f4f6ffe1 (diff)
Fix X86FastISel's add folding to actually work, and not fall back
to SelectionDAG. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107376 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/X86/X86FastISel.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp
index f371796141..1c700b290a 100644
--- a/lib/Target/X86/X86FastISel.cpp
+++ b/lib/Target/X86/X86FastISel.cpp
@@ -430,6 +430,14 @@ bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
// Constant-offset addressing.
Disp += CI->getSExtValue() * S;
+ } else if (isa<AddOperator>(Op) &&
+ isa<ConstantInt>(cast<AddOperator>(Op)->getOperand(1))) {
+ // An add with a constant operand. Fold the constant.
+ ConstantInt *CI =
+ cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
+ Disp += CI->getSExtValue() * S;
+ // Add the other operand back to the work list.
+ Worklist.push_back(cast<AddOperator>(Op)->getOperand(0));
} else if (IndexReg == 0 &&
(!AM.GV || !Subtarget->isPICStyleRIPRel()) &&
(S == 1 || S == 2 || S == 4 || S == 8)) {
@@ -438,10 +446,6 @@ bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) {
IndexReg = getRegForGEPIndex(Op).first;
if (IndexReg == 0)
return false;
- } else if (const AddOperator *Add = dyn_cast<AddOperator>(Op)) {
- // An add. Try to fold both operands.
- Worklist.push_back(Add->getOperand(0));
- Worklist.push_back(Add->getOperand(1));
} else
// Unsupported.
goto unsupported_gep;