Look through addrspacecast in IsConstantOffsetFromGlobal

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213000 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault 2014-07-14 22:39:26 +00:00
parent 19d44f6ac1
commit ff985d4218
2 changed files with 15 additions and 1 deletions

View File

@ -240,7 +240,8 @@ static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
// Look through ptr->int and ptr->ptr casts.
if (CE->getOpcode() == Instruction::PtrToInt ||
CE->getOpcode() == Instruction::BitCast)
CE->getOpcode() == Instruction::BitCast ||
CE->getOpcode() == Instruction::AddrSpaceCast)
return IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, TD);
// i32* getelementptr ([5 x i32]* @a, i32 0, i32 5)

View File

@ -36,6 +36,19 @@ define i16 @test2() {
; BE: ret i16 -8531
}
define i16 @test2_addrspacecast() {
%r = load i16 addrspace(1)* addrspacecast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16 addrspace(1)*)
ret i16 %r
; 0xBEEF
; LE-LABEL: @test2_addrspacecast(
; LE: ret i16 -16657
; 0xDEAD
; BE-LABEL: @test2_addrspacecast(
; BE: ret i16 -8531
}
; Load of second 16 bits of 32-bit value.
define i16 @test3() {
%r = load i16* getelementptr(i16* bitcast(i32* getelementptr ({{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16*), i32 1)