From ff985d421880a5d39077f25db9117c7301f3f79d Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 14 Jul 2014 22:39:26 +0000 Subject: [PATCH] Look through addrspacecast in IsConstantOffsetFromGlobal git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213000 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantFolding.cpp | 3 ++- test/Transforms/ConstProp/loads.ll | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index eb3e2c63690..8dc94219027 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -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) diff --git a/test/Transforms/ConstProp/loads.ll b/test/Transforms/ConstProp/loads.ll index 0ea9c47d448..5a23dad87f3 100644 --- a/test/Transforms/ConstProp/loads.ll +++ b/test/Transforms/ConstProp/loads.ll @@ -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)