[llvm-commits] [llvm] r97813 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombinePHI.cpp test/Transforms/InstCombine/phi.ll
Chris Lattner
sabre at nondot.org
Fri Mar 5 10:53:28 PST 2010
Author: lattner
Date: Fri Mar 5 12:53:28 2010
New Revision: 97813
URL: http://llvm.org/viewvc/llvm-project?rev=97813&view=rev
Log:
fix PR6512, a case where instcombine would incorrectly merge loads
from different addr spaces.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
llvm/trunk/test/Transforms/InstCombine/phi.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp?rev=97813&r1=97812&r2=97813&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp Fri Mar 5 12:53:28 2010
@@ -266,6 +266,7 @@
// and if TD isn't around, we can't handle the mixed case.
bool isVolatile = FirstLI->isVolatile();
unsigned LoadAlignment = FirstLI->getAlignment();
+ unsigned LoadAddrSpace = FirstLI->getPointerAddressSpace();
// We can't sink the load if the loaded value could be modified between the
// load and the PHI.
@@ -290,6 +291,7 @@
// the load and the PHI.
if (LI->isVolatile() != isVolatile ||
LI->getParent() != PN.getIncomingBlock(i) ||
+ LI->getPointerAddressSpace() != LoadAddrSpace ||
!isSafeAndProfitableToSinkLoad(LI))
return 0;
Modified: llvm/trunk/test/Transforms/InstCombine/phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/phi.ll?rev=97813&r1=97812&r2=97813&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/phi.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/phi.ll Fri Mar 5 12:53:28 2010
@@ -362,3 +362,43 @@
; CHECK-NEXT: ret i64
}
+; PR6512 - Shouldn't merge loads from different addr spaces.
+define i32 @test16(i32 addrspace(1)* %pointer1, i32 %flag, i32* %pointer2)
+nounwind {
+entry:
+ %retval = alloca i32, align 4 ; <i32*> [#uses=2]
+ %pointer1.addr = alloca i32 addrspace(1)*, align 4 ; <i32 addrspace(1)**>
+ %flag.addr = alloca i32, align 4 ; <i32*> [#uses=2]
+ %pointer2.addr = alloca i32*, align 4 ; <i32**> [#uses=2]
+ %res = alloca i32, align 4 ; <i32*> [#uses=4]
+ store i32 addrspace(1)* %pointer1, i32 addrspace(1)** %pointer1.addr
+ store i32 %flag, i32* %flag.addr
+ store i32* %pointer2, i32** %pointer2.addr
+ store i32 10, i32* %res
+ %tmp = load i32* %flag.addr ; <i32> [#uses=1]
+ %tobool = icmp ne i32 %tmp, 0 ; <i1> [#uses=1]
+ br i1 %tobool, label %if.then, label %if.else
+
+return: ; preds = %if.end
+ %tmp7 = load i32* %retval ; <i32> [#uses=1]
+ ret i32 %tmp7
+
+if.end: ; preds = %if.else, %if.then
+ %tmp6 = load i32* %res ; <i32> [#uses=1]
+ store i32 %tmp6, i32* %retval
+ br label %return
+
+if.then: ; preds = %entry
+ %tmp1 = load i32 addrspace(1)** %pointer1.addr ; <i32 addrspace(1)*>
+ %arrayidx = getelementptr i32 addrspace(1)* %tmp1, i32 0 ; <i32 addrspace(1)*> [#uses=1]
+ %tmp2 = load i32 addrspace(1)* %arrayidx ; <i32> [#uses=1]
+ store i32 %tmp2, i32* %res
+ br label %if.end
+
+if.else: ; preds = %entry
+ %tmp3 = load i32** %pointer2.addr ; <i32*> [#uses=1]
+ %arrayidx4 = getelementptr i32* %tmp3, i32 0 ; <i32*> [#uses=1]
+ %tmp5 = load i32* %arrayidx4 ; <i32> [#uses=1]
+ store i32 %tmp5, i32* %res
+ br label %if.end
+}
More information about the llvm-commits
mailing list