Allow i16 type indices to gep.
authorSanjiv Gupta <sanjiv.gupta@microchip.com>
Fri, 24 Apr 2009 02:37:54 +0000 (02:37 +0000)
committerSanjiv Gupta <sanjiv.gupta@microchip.com>
Fri, 24 Apr 2009 02:37:54 +0000 (02:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69946 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LangRef.html
lib/Transforms/Scalar/InstructionCombining.cpp
lib/VMCore/Type.cpp

index 8ec11235dc2067495e23630833c63655d26a4893..587f981665f7ac61030ff0da54a1c68a595ece18 100644 (file)
@@ -3629,7 +3629,8 @@ the pointer before continuing calculation.</p>
 <p>The type of each index argument depends on the type it is indexing into.
 When indexing into a (packed) structure, only <tt>i32</tt> integer
 <b>constants</b> 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.</p>
 
 <p>For example, let's consider a C code fragment and how it gets
@@ -3717,6 +3718,8 @@ FAQ</a>.</p>
     %vptr = getelementptr {i32, &lt;2 x i8&gt;}* %svptr, i64 0, i32 1, i32 1
     <i>; yields i8*:eptr</i>
     %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1
+    <i>; yields i16*:iptr</i>
+    %iptr = getelementptr [10 x i16]* @arr, i16 0, i16 0
 </pre>
 </div>
 
index 0d32eacbb1703b497fc23e3a00018cde89a2c24a..a2658b3e3f1177e8f5d31436930ef5ebf8e40c7b 100644 (file)
@@ -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<SequentialType>(*GTI);
-    Value *PtrTypeVal = Constant::getNullValue(TD->getIntPtrType());
-    if (ST && ST->indexValid(PtrTypeVal)) {
+    if (isa<SequentialType>(*GTI)) {
       if (CastInst *CI = dyn_cast<CastInst>(*i)) {
         if (CI->getOpcode() == Instruction::ZExt ||
             CI->getOpcode() == Instruction::SExt) {
index 7e6bbe511fecb04350649e1eeffae232a38fd1f7..c85395f6201134e3e84e2e956566f0a7092c985e 100644 (file)
@@ -1411,7 +1411,8 @@ void PointerType::typeBecameConcrete(const DerivedType *AbsTy) {
 
 bool SequentialType::indexValid(const Value *V) const {
   if (const IntegerType *IT = dyn_cast<IntegerType>(V->getType())) 
-    return IT->getBitWidth() == 32 || IT->getBitWidth() == 64;
+    return IT->getBitWidth() == 16 || IT->getBitWidth() == 32 ||
+           IT->getBitWidth() == 64;
   return false;
 }