1 ; RUN: opt -sroa -S < %s | FileCheck %s
3 ; This test checks that SROA does not introduce ptrtoint and inttoptr
4 ; casts from and to non-integral pointers. The "ni:4" bit in the
5 ; datalayout states that pointers of address space 4 are to be
6 ; considered "non-integral".
8 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4"
9 target triple = "x86_64-unknown-linux-gnu"
11 define void @f0(i1 %alwaysFalse, i64 %val) {
17 store i64 %val, i64* %loc
18 br i1 %alwaysFalse, label %neverTaken, label %alwaysTaken
21 %loc.bc = bitcast i64* %loc to i8 addrspace(4)**
22 %ptr = load i8 addrspace(4)*, i8 addrspace(4)** %loc.bc
23 store i8 5, i8 addrspace(4)* %ptr
30 define i64 @f1(i1 %alwaysFalse, i8 addrspace(4)* %val) {
35 %loc = alloca i8 addrspace(4)*
36 store i8 addrspace(4)* %val, i8 addrspace(4)** %loc
37 br i1 %alwaysFalse, label %neverTaken, label %alwaysTaken
40 %loc.bc = bitcast i8 addrspace(4)** %loc to i64*
41 %int = load i64, i64* %loc.bc
48 define i64 addrspace(4)* @memset(i1 %alwaysFalse) {
49 ; CHECK-LABEL: @memset(
53 %x = alloca i64 addrspace(4)*
54 %cast.0 = bitcast i64 addrspace(4)** %x to i8*
55 call void @llvm.memset.p0i8.i64(i8* align 8 %cast.0, i8 5, i64 16, i1 false)
56 br i1 %alwaysFalse, label %neverTaken, label %alwaysTaken
59 %x.field.ld.0 = load i64 addrspace(4)*, i64 addrspace(4)** %x
60 ret i64 addrspace(4)* %x.field.ld.0
63 ret i64 addrspace(4)* null
66 ;; TODO: This one demonstrates a missed oppurtunity. The only known bit
67 ;; pattern for a non-integral bit pattern is that null is zero. As such
68 ;; we could do SROA and replace the memset w/a null store. This will
69 ;; usually be gotten by instcombine.
70 define i64 addrspace(4)* @memset_null(i1 %alwaysFalse) {
71 ; CHECK-LABEL: @memset_null(
75 %x = alloca i64 addrspace(4)*
76 %cast.0 = bitcast i64 addrspace(4)** %x to i8*
77 call void @llvm.memset.p0i8.i64(i8* align 8 %cast.0, i8 0, i64 16, i1 false)
78 br i1 %alwaysFalse, label %neverTaken, label %alwaysTaken
81 %x.field.ld.0 = load i64 addrspace(4)*, i64 addrspace(4)** %x
82 ret i64 addrspace(4)* %x.field.ld.0
85 ret i64 addrspace(4)* null
88 %union.anon = type { i32* }
93 define i8 *@f2(i8 addrspace(4)* %p) {
94 %1 = alloca %union.anon, align 8
95 %2 = bitcast %union.anon* %1 to i8 addrspace(4)**
96 store i8 addrspace(4)* %p, i8 addrspace(4)** %2, align 8
97 %3 = bitcast %union.anon* %1 to i8**
98 %4 = load i8*, i8** %3, align 8
102 declare void @llvm.memset.p0i8.i64(i8*, i8, i64, i1)