[llvm] r213000 - Look through addrspacecast in IsConstantOffsetFromGlobal
Matt Arsenault
Matthew.Arsenault at amd.com
Mon Jul 14 15:39:26 PDT 2014
Author: arsenm
Date: Mon Jul 14 17:39:26 2014
New Revision: 213000
URL: http://llvm.org/viewvc/llvm-project?rev=213000&view=rev
Log:
Look through addrspacecast in IsConstantOffsetFromGlobal
Modified:
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/test/Transforms/ConstProp/loads.ll
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=213000&r1=212999&r2=213000&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Mon Jul 14 17:39:26 2014
@@ -240,7 +240,8 @@ static bool IsConstantOffsetFromGlobal(C
// 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)
Modified: llvm/trunk/test/Transforms/ConstProp/loads.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/loads.ll?rev=213000&r1=212999&r2=213000&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/loads.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/loads.ll Mon Jul 14 17:39:26 2014
@@ -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)
More information about the llvm-commits
mailing list