OSDN Git Service

[InstCombine] Do not RAUW a constant GEP
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 15 Sep 2016 20:10:09 +0000 (20:10 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 15 Sep 2016 20:10:09 +0000 (20:10 +0000)
canRewriteGEPAsOffset expects to process instructions, not constants.

This fixes PR30342.

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

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/indexed-gep-compares.ll

index 56fa933..9604448 100644 (file)
@@ -625,7 +625,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
       }
 
       if (!isa<IntToPtrInst>(V) && !isa<PtrToIntInst>(V) &&
-          !isa<GEPOperator>(V) && !isa<PHINode>(V))
+          !isa<GetElementPtrInst>(V) && !isa<PHINode>(V))
         // We've found some value that we can't explore which is different from
         // the base. Therefore we can't do this transformation.
         return false;
index 4958815..64dff27 100644 (file)
@@ -167,4 +167,24 @@ lpad:
 ; CHECK:  ret i32* %[[PTR]]
 }
 
+
+@pr30402 = constant i64 3
+define i1 @test7() {
+entry:
+  br label %bb7
+
+bb7:                                              ; preds = %bb10, %entry-block
+  %phi = phi i64* [ @pr30402, %entry ], [ getelementptr inbounds (i64, i64* @pr30402, i32 1), %bb7 ]
+  %cmp = icmp eq i64* %phi, getelementptr inbounds (i64, i64* @pr30402, i32 1)
+  br i1 %cmp, label %bb10, label %bb7
+
+bb10:
+  ret i1 %cmp
+}
+; CHECK-LABEL: @test7(
+; CHECK:  %[[phi:.*]] = phi i64* [ @pr30402, %entry ], [ getelementptr inbounds (i64, i64* @pr30402, i32 1), %bb7 ]
+; CHECK:  %[[cmp:.*]] = icmp eq i64* %[[phi]], getelementptr inbounds (i64, i64* @pr30402, i32 1)
+; CHECK: ret i1 %[[cmp]]
+
+
 declare i32 @__gxx_personality_v0(...)