fix PR6512, a case where instcombine would incorrectly merge loads

from different addr spaces.

llvm-svn: 97813
This commit is contained in:
Chris Lattner 2010-03-05 18:53:28 +00:00
parent 79c2f7afcc
commit 789121d6e2
2 changed files with 42 additions and 0 deletions

View File

@ -266,6 +266,7 @@ Instruction *InstCombiner::FoldPHIArgLoadIntoPHI(PHINode &PN) {
// 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 @@ Instruction *InstCombiner::FoldPHIArgLoadIntoPHI(PHINode &PN) {
// the load and the PHI.
if (LI->isVolatile() != isVolatile ||
LI->getParent() != PN.getIncomingBlock(i) ||
LI->getPointerAddressSpace() != LoadAddrSpace ||
!isSafeAndProfitableToSinkLoad(LI))
return 0;

View File

@ -362,3 +362,43 @@ end:
; 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
}