From 4f833d435147f98329ae015140ca2b6ea530b717 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 11 Sep 2008 23:06:38 +0000 Subject: 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 --- lib/Transforms/Scalar/InstructionCombining.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/Transforms') 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(Op)) { + *i = ConstantExpr::getSExt(C, TD->getIntPtrType()); + MadeChange = true; + } else { + Op = InsertCastBefore(Instruction::SExt, Op, TD->getIntPtrType(), + GEP); + *i = Op; + MadeChange = true; + } } } } -- cgit v1.2.3