diff options
author | Dan Gohman <gohman@apple.com> | 2008-09-11 23:06:38 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-09-11 23:06:38 +0000 |
commit | 5d639edbea1b68762a9c529b042792aa82e8b651 (patch) | |
tree | 5245be0deea50b18408cea59ef1f59e0230d5965 /lib | |
parent | 83b702d808bbd13425534ebce798c4524f2796bd (diff) | |
download | external_llvm-5d639edbea1b68762a9c529b042792aa82e8b651.zip external_llvm-5d639edbea1b68762a9c529b042792aa82e8b651.tar.gz external_llvm-5d639edbea1b68762a9c529b042792aa82e8b651.tar.bz2 |
On 64-bit targets, change 32-bit getelementptr indices to be 64-bit
getelementptr indices, inserting an explicit cast if necessary.
This helps expose the sign-extension operation to other optimizations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56133 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index f02a710..1cb4fa2 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -9795,7 +9795,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } } // If we are using a wider index than needed for this platform, shrink it - // to what we need. If the incoming value needs a cast instruction, + // to what we need. If narrower, sign-extend it to what we need. + // If the incoming value needs a cast instruction, // insert it. This explicit cast can make subsequent optimizations more // obvious. Value *Op = *i; @@ -9809,6 +9810,16 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { *i = Op; MadeChange = true; } + } else if (TD->getTypeSizeInBits(Op->getType()) < TD->getPointerSizeInBits()) { + if (Constant *C = dyn_cast<Constant>(Op)) { + *i = ConstantExpr::getSExt(C, TD->getIntPtrType()); + MadeChange = true; + } else { + Op = InsertCastBefore(Instruction::SExt, Op, TD->getIntPtrType(), + GEP); + *i = Op; + MadeChange = true; + } } } } |