diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-01 02:27:15 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-01 02:27:15 +0000 |
commit | 5c87bf64d63fa90107912ff7f94484bfa35379c7 (patch) | |
tree | 53dd4cf695b1f7f33e9b2e5d84d3e2a384b1d0c2 /lib | |
parent | 28a173581c67cda78b2febd24d10edb13f760c4c (diff) | |
download | llvm-5c87bf64d63fa90107912ff7f94484bfa35379c7.tar.gz llvm-5c87bf64d63fa90107912ff7f94484bfa35379c7.tar.bz2 llvm-5c87bf64d63fa90107912ff7f94484bfa35379c7.tar.xz |
Teach X86FastISel to fold constant offsets and scaled indices in
the same address.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107373 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/X86/X86FastISel.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index 0338203d35..f371796141 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -423,20 +423,29 @@ bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) { Disp += SL->getElementOffset(Idx); } else { uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType()); - if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { - // Constant-offset addressing. - Disp += CI->getSExtValue() * S; - } else if (IndexReg == 0 && - (!AM.GV || !Subtarget->isPICStyleRIPRel()) && - (S == 1 || S == 2 || S == 4 || S == 8)) { - // Scaled-index addressing. - Scale = S; - IndexReg = getRegForGEPIndex(Op).first; - if (IndexReg == 0) - return false; - } else - // Unsupported. - goto unsupported_gep; + SmallVector<const Value *, 4> Worklist; + Worklist.push_back(Op); + do { + Op = Worklist.pop_back_val(); + if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { + // Constant-offset addressing. + Disp += CI->getSExtValue() * S; + } else if (IndexReg == 0 && + (!AM.GV || !Subtarget->isPICStyleRIPRel()) && + (S == 1 || S == 2 || S == 4 || S == 8)) { + // Scaled-index addressing. + Scale = S; + 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; + } while (!Worklist.empty()); } } // Check for displacement overflow. |