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 | 7937d5606d85d79fe6cbccef739701d2769fc520 (patch) | |
| tree | aac5f32cccb05aa187fd0ebb6bb4c7d8a8f4e624 /llvm/lib | |
| parent | fb0c0d37b7f2d15cf34595b99793ecdbb97a931d (diff) | |
| download | bcm5719-llvm-7937d5606d85d79fe6cbccef739701d2769fc520.tar.gz bcm5719-llvm-7937d5606d85d79fe6cbccef739701d2769fc520.zip | |
Teach X86FastISel to fold constant offsets and scaled indices in
the same address.
llvm-svn: 107373
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/X86/X86FastISel.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp index 0338203d35d..f371796141d 100644 --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/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. |

