Before trying to introduce/eliminate cast/ext/trunc to make indices type as
authorSanjiv Gupta <sanjiv.gupta@microchip.com>
Mon, 20 Apr 2009 06:05:54 +0000 (06:05 +0000)
committerSanjiv Gupta <sanjiv.gupta@microchip.com>
Mon, 20 Apr 2009 06:05:54 +0000 (06:05 +0000)
pointer type, make sure that the pointer size is a valid sequential index type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69574 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index a2658b3e3f1177e8f5d31436930ef5ebf8e40c7b..0d32eacbb1703b497fc23e3a00018cde89a2c24a 100644 (file)
@@ -10695,7 +10695,12 @@ 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) {
-    if (isa<SequentialType>(*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 (CastInst *CI = dyn_cast<CastInst>(*i)) {
         if (CI->getOpcode() == Instruction::ZExt ||
             CI->getOpcode() == Instruction::SExt) {