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 | 4f833d435147f98329ae015140ca2b6ea530b717 (patch) | |
tree | 5245be0deea50b18408cea59ef1f59e0230d5965 /lib/Transforms | |
parent | 3139ff8f7b5e3eeb170d77ac8472fc4ca596ec0e (diff) | |
download | llvm-4f833d435147f98329ae015140ca2b6ea530b717.tar.gz llvm-4f833d435147f98329ae015140ca2b6ea530b717.tar.bz2 llvm-4f833d435147f98329ae015140ca2b6ea530b717.tar.xz |
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/Transforms')
-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 f02a7108fd..1cb4fa2c21 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; + } } } } |