[PATCH] D41114: Look through address space casts in IsConstantOffsetFromGlobal()
Alexander Richardson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 08:04:46 PST 2017
arichardson created this revision.
arichardson added reviewers: lattner, arsenm, mehdi_amini.
Herald added a subscriber: wdng.
I originally needed this change for our fork of clang targeting CHERI which
uses address space 200 extensively. It turns out the only test that fails
after this change is Transforms/ConstProp/loads.ll which already contains
a FIXME for this case.
https://reviews.llvm.org/D41114
Files:
lib/Analysis/ConstantFolding.cpp
test/Transforms/ConstProp/loads.ll
Index: test/Transforms/ConstProp/loads.ll
===================================================================
--- test/Transforms/ConstProp/loads.ll
+++ test/Transforms/ConstProp/loads.ll
@@ -40,16 +40,13 @@
%r = load i16, i16 addrspace(1)* addrspacecast(i32* getelementptr ({{i32,i8},i32}, {{i32,i8},i32}* @g1, i32 0, i32 0, i32 0) to i16 addrspace(1)*)
ret i16 %r
-; FIXME: Should be able to load through a constant addrspacecast.
; 0xBEEF
; LE-LABEL: @test2_addrspacecast(
-; XLE: ret i16 -16657
-; LE: load i16, i16 addrspace(1)* addrspacecast
+; LE: ret i16 -16657
; 0xDEAD
; BE-LABEL: @test2_addrspacecast(
-; XBE: ret i16 -8531
-; BE: load i16, i16 addrspace(1)* addrspacecast
+; BE: ret i16 -8531
}
; Load of second 16 bits of 32-bit value.
Index: lib/Analysis/ConstantFolding.cpp
===================================================================
--- lib/Analysis/ConstantFolding.cpp
+++ lib/Analysis/ConstantFolding.cpp
@@ -295,9 +295,10 @@
auto *CE = dyn_cast<ConstantExpr>(C);
if (!CE) return false;
- // Look through ptr->int and ptr->ptr casts.
+ // Look through ptr->int, ptr->ptr casts and address space 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, DL);
// i32* getelementptr ([5 x i32]* @a, i32 0, i32 5)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41114.126552.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171212/e344087e/attachment.bin>
More information about the llvm-commits
mailing list