]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Fix bug in pointer replacement
authorYaxun Liu <Yaxun.Liu@amd.com>
Fri, 24 Feb 2017 20:27:25 +0000 (20:27 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Fri, 24 Feb 2017 20:27:25 +0000 (20:27 +0000)
This optimisation was crashing when there was a chain of more than one bitcast
instruction to replace, as a result of the changes in D27283.

Patch by James Price.

Differential Revision: https://reviews.llvm.org/D30347

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

lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Transforms/InstCombine/memcpy-addrspace.ll

index d9e83f6516d305d44e2faf49d00c82eabca1a4fe..6288e054f1bc57c9f285f04ac89a416d9bb9a761 100644 (file)
@@ -309,7 +309,7 @@ void PointerReplacer::replace(Instruction *I) {
     auto *NewI = new BitCastInst(V, NewT);
     IC.InsertNewInstWith(NewI, *BC);
     NewI->takeName(BC);
-    WorkMap[GEP] = NewI;
+    WorkMap[BC] = NewI;
   } else {
     llvm_unreachable("should never reach here");
   }
index 2b80f2f51e5e7ac63b5ec02363647715da07d35c..17bc1d08f98675cc62504b25a7edda339f72ff3f 100644 (file)
@@ -21,6 +21,26 @@ entry:
   ret void
 }
 
+; CHECK-LABEL: test_load_bitcast_chain
+; CHECK: %[[GEP:.*]] = getelementptr [8 x i32], [8 x i32] addrspace(2)* @test.data, i64 0, i64 %x
+; CHECK: %{{.*}} = load i32, i32 addrspace(2)* %[[GEP]]
+; CHECK-NOT: alloca
+; CHECK-NOT: call void @llvm.memcpy.p0i8.p2i8.i64
+; CHECK-NOT: addrspacecast
+; CHECK-NOT: load i32, i32*
+define void @test_load_bitcast_chain(i32 addrspace(1)* %out, i64 %x) {
+entry:
+  %data = alloca [8 x i32], align 4
+  %0 = bitcast [8 x i32]* %data to i8*
+  call void @llvm.memcpy.p0i8.p2i8.i64(i8* %0, i8 addrspace(2)* bitcast ([8 x i32] addrspace(2)* @test.data to i8 addrspace(2)*), i64 32, i32 4, i1 false)
+  %1 = bitcast i8* %0 to i32*
+  %arrayidx = getelementptr inbounds i32, i32* %1, i64 %x
+  %2 = load i32, i32* %arrayidx, align 4
+  %arrayidx1 = getelementptr inbounds i32, i32 addrspace(1)* %out, i64 %x
+  store i32 %2, i32 addrspace(1)* %arrayidx1, align 4
+  ret void
+}
+
 ; CHECK-LABEL: test_call
 ; CHECK: alloca
 ; CHECK: call void @llvm.memcpy.p0i8.p2i8.i64