OSDN Git Service

ConstantFold: Fold getelementptr (i32, i32* null, i64 undef) to null.
authorDaniel Berlin <dberlin@dberlin.org>
Mon, 8 May 2017 17:37:29 +0000 (17:37 +0000)
committerDaniel Berlin <dberlin@dberlin.org>
Mon, 8 May 2017 17:37:29 +0000 (17:37 +0000)
Transforms/IndVarSimplify/2011-10-27-lftrnull will fail if this regresses.
Transforms/GVN/PRE/2011-06-01-NonLocalMemdepMiscompile.ll has been changed to still test what it was
trying to test.

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

lib/IR/ConstantFold.cpp
test/Transforms/GVN/PRE/2011-06-01-NonLocalMemdepMiscompile.ll
test/Transforms/IndVarSimplify/2011-10-27-lftrnull.ll

index 80b1170..c185933 100644 (file)
@@ -2054,7 +2054,8 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
   if (C->isNullValue()) {
     bool isNull = true;
     for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
-      if (!cast<Constant>(Idxs[i])->isNullValue()) {
+      if (!isa<UndefValue>(Idxs[i]) &&
+          !cast<Constant>(Idxs[i])->isNullValue()) {
         isNull = false;
         break;
       }
index 0769575..05dc79d 100644 (file)
@@ -5,8 +5,7 @@
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-apple-macosx10.7.0"
-
-define i1 @rb_intern() nounwind ssp {
+define i1 @rb_intern(i8 *%foo) nounwind ssp {
 ; CHECK-LABEL: @rb_intern(
 
 bb:
@@ -19,7 +18,7 @@ bb1:
   br i1 undef, label %bb3, label %bb15
 
 ; CHECK: bb1:
-; CHECK: [[TMP:%.*]] = phi i8* [ getelementptr (i8, i8* null, i64 undef), %bb10 ], [ null, %bb ]
+; CHECK: [[TMP:%.*]] = phi i8* [ %tmp14, %bb10 ], [ null, %bb ]
 
 ; CHECK: bb1.bb15_crit_edge:
 ; CHECK: %tmp17.pre = load i8, i8* [[TMP]], align 1
@@ -41,7 +40,7 @@ bb10:
   %tmp11 = load i8*, i8** %tmp, align 8
   %tmp12 = load i8, i8* %tmp11, align 1
   %tmp13 = zext i8 %tmp12 to i64
-  %tmp14 = getelementptr inbounds i8, i8* null, i64 undef
+  %tmp14 = getelementptr inbounds i8, i8* %foo, i64 undef
   store i8* %tmp14, i8** %tmp, align 8
   br label %bb1
 
index 3d77a36..49e5d24 100644 (file)
@@ -6,7 +6,7 @@ target triple = "thumbv7-apple-darwin"
 
 ; CHECK-LABEL: @test(
 ; CHECK: if.end.i126:
-; CHECK: %exitcond = icmp ne i8* %incdec.ptr.i, getelementptr (i8, i8* null, i32 undef)
+; CHECK: %exitcond = icmp ne i8* %incdec.ptr.i, null
 define void @test() nounwind {
 entry:
   br label %while.cond