diff options
author | Meador Inge <meadori@codesourcery.com> | 2013-02-27 02:26:42 +0000 |
---|---|---|
committer | Meador Inge <meadori@codesourcery.com> | 2013-02-27 02:26:42 +0000 |
commit | 8df7c39976890d94198d835e032848a374fec158 (patch) | |
tree | 720c2f50e52f22799557139f939fdf79d84ce37f /test/Other | |
parent | 5e5974f51ad079a3ed890ca8be1d3f50150320ad (diff) | |
download | llvm-8df7c39976890d94198d835e032848a374fec158.tar.gz llvm-8df7c39976890d94198d835e032848a374fec158.tar.bz2 llvm-8df7c39976890d94198d835e032848a374fec158.tar.xz |
IR: Don't constant fold GEP bitcasts between different address spaces
PR15262 reported a bug where the following instruction:
i8 getelementptr inbounds i8* bitcast ([4 x i8] addrspace(12)* @buf to i8*),
i32 2
was getting folded into:
addrspace(12)* getelementptr inbounds ([4 x i8] addrspace(12)* @buf, i32 0,
i32 2)
This caused instcombine to crash because the original instruction and
the folded instruction have different types. The issue was fixed by
disallowing bitcasts between different address spaces to be folded away.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176156 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Other')
-rw-r--r-- | test/Other/constant-fold-gep.ll | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/Other/constant-fold-gep.ll b/test/Other/constant-fold-gep.ll index 0224e9f984..44b66284dd 100644 --- a/test/Other/constant-fold-gep.ll +++ b/test/Other/constant-fold-gep.ll @@ -447,4 +447,24 @@ define i32* @fZ() nounwind { ret i32* %t } +; PR15262 - Check GEP folding with casts between address spaces. + +@p0 = global [4 x i8] zeroinitializer, align 1 +@p12 = addrspace(12) global [4 x i8] zeroinitializer, align 1 + +define i8* @different_addrspace() nounwind noinline { +; OPT: different_addrspace + %p = getelementptr inbounds i8* bitcast ([4 x i8] addrspace(12)* @p12 to i8*), + i32 2 + ret i8* %p +; OPT: ret i8* getelementptr (i8* bitcast ([4 x i8] addrspace(12)* @p12 to i8*), i32 2) +} + +define i8* @same_addrspace() nounwind noinline { +; OPT: same_addrspace + %p = getelementptr inbounds i8* bitcast ([4 x i8] * @p0 to i8*), i32 2 + ret i8* %p +; OPT: ret i8* getelementptr inbounds ([4 x i8]* @p0, i32 0, i32 2) +} + ; CHECK: attributes #0 = { nounwind } |