From 46c97e626f0c99bc271f212242446186ed3c2474 Mon Sep 17 00:00:00 2001 From: Sanjiv Gupta Date: Fri, 24 Apr 2009 02:37:54 +0000 Subject: [PATCH] Allow i16 type indices to gep. llvm-svn: 69946 --- llvm/docs/LangRef.html | 5 ++++- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 7 +------ llvm/lib/VMCore/Type.cpp | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/llvm/docs/LangRef.html b/llvm/docs/LangRef.html index 8ec11235dc20..587f981665f7 100644 --- a/llvm/docs/LangRef.html +++ b/llvm/docs/LangRef.html @@ -3629,7 +3629,8 @@ the pointer before continuing calculation.

The type of each index argument depends on the type it is indexing into. When indexing into a (packed) structure, only i32 integer constants are allowed. When indexing into an array, pointer or vector, -only integers of 32 or 64 bits are allowed (also non-constants). 32-bit values +only integers of 16, 32 or 64 bits are allowed (also non-constants).16-bit +values will be sign extended to 32-bits if required, and 32-bit values will be sign extended to 64-bits if required.

For example, let's consider a C code fragment and how it gets @@ -3717,6 +3718,8 @@ FAQ.

%vptr = getelementptr {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 ; yields i8*:eptr %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1 + ; yields i16*:iptr + %iptr = getelementptr [10 x i16]* @arr, i16 0, i16 0 diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 0d32eacbb170..a2658b3e3f11 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -10695,12 +10695,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { gep_type_iterator GTI = gep_type_begin(GEP); for (User::op_iterator i = GEP.op_begin() + 1, e = GEP.op_end(); i != e; ++i, ++GTI) { - // Before trying to eliminate/introduce cast/ext/trunc to make - // indices as pointer types, make sure that the pointer size - // makes a valid sequential index. - const SequentialType *ST = dyn_cast(*GTI); - Value *PtrTypeVal = Constant::getNullValue(TD->getIntPtrType()); - if (ST && ST->indexValid(PtrTypeVal)) { + if (isa(*GTI)) { if (CastInst *CI = dyn_cast(*i)) { if (CI->getOpcode() == Instruction::ZExt || CI->getOpcode() == Instruction::SExt) { diff --git a/llvm/lib/VMCore/Type.cpp b/llvm/lib/VMCore/Type.cpp index 7e6bbe511fec..c85395f62011 100644 --- a/llvm/lib/VMCore/Type.cpp +++ b/llvm/lib/VMCore/Type.cpp @@ -1411,7 +1411,8 @@ void PointerType::typeBecameConcrete(const DerivedType *AbsTy) { bool SequentialType::indexValid(const Value *V) const { if (const IntegerType *IT = dyn_cast(V->getType())) - return IT->getBitWidth() == 32 || IT->getBitWidth() == 64; + return IT->getBitWidth() == 16 || IT->getBitWidth() == 32 || + IT->getBitWidth() == 64; return false; }