Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGenSYCL / address-space-deduction.cpp
blob5910ec3bfc305a2ca93eea2c33a5a3bef8b12e1d
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2 // RUN: %clang_cc1 -triple spir64 -fsycl-is-device -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
4 // CHECK-LABEL: @_Z4testv(
5 // CHECK-NEXT: entry:
6 // CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
7 // CHECK-NEXT: [[PPTR:%.*]] = alloca ptr addrspace(4), align 8
8 // CHECK-NEXT: [[IS_I_PTR:%.*]] = alloca i8, align 1
9 // CHECK-NEXT: [[VAR23:%.*]] = alloca i32, align 4
10 // CHECK-NEXT: [[CP:%.*]] = alloca ptr addrspace(4), align 8
11 // CHECK-NEXT: [[ARR:%.*]] = alloca [42 x i32], align 4
12 // CHECK-NEXT: [[CPP:%.*]] = alloca ptr addrspace(4), align 8
13 // CHECK-NEXT: [[APTR:%.*]] = alloca ptr addrspace(4), align 8
14 // CHECK-NEXT: [[STR:%.*]] = alloca ptr addrspace(4), align 8
15 // CHECK-NEXT: [[PHI_STR:%.*]] = alloca ptr addrspace(4), align 8
16 // CHECK-NEXT: [[SELECT_NULL:%.*]] = alloca ptr addrspace(4), align 8
17 // CHECK-NEXT: [[SELECT_STR_TRIVIAL1:%.*]] = alloca ptr addrspace(4), align 8
18 // CHECK-NEXT: [[SELECT_STR_TRIVIAL2:%.*]] = alloca ptr addrspace(4), align 8
19 // CHECK-NEXT: [[I_ASCAST:%.*]] = addrspacecast ptr [[I]] to ptr addrspace(4)
20 // CHECK-NEXT: [[PPTR_ASCAST:%.*]] = addrspacecast ptr [[PPTR]] to ptr addrspace(4)
21 // CHECK-NEXT: [[IS_I_PTR_ASCAST:%.*]] = addrspacecast ptr [[IS_I_PTR]] to ptr addrspace(4)
22 // CHECK-NEXT: [[VAR23_ASCAST:%.*]] = addrspacecast ptr [[VAR23]] to ptr addrspace(4)
23 // CHECK-NEXT: [[CP_ASCAST:%.*]] = addrspacecast ptr [[CP]] to ptr addrspace(4)
24 // CHECK-NEXT: [[ARR_ASCAST:%.*]] = addrspacecast ptr [[ARR]] to ptr addrspace(4)
25 // CHECK-NEXT: [[CPP_ASCAST:%.*]] = addrspacecast ptr [[CPP]] to ptr addrspace(4)
26 // CHECK-NEXT: [[APTR_ASCAST:%.*]] = addrspacecast ptr [[APTR]] to ptr addrspace(4)
27 // CHECK-NEXT: [[STR_ASCAST:%.*]] = addrspacecast ptr [[STR]] to ptr addrspace(4)
28 // CHECK-NEXT: [[PHI_STR_ASCAST:%.*]] = addrspacecast ptr [[PHI_STR]] to ptr addrspace(4)
29 // CHECK-NEXT: [[SELECT_NULL_ASCAST:%.*]] = addrspacecast ptr [[SELECT_NULL]] to ptr addrspace(4)
30 // CHECK-NEXT: [[SELECT_STR_TRIVIAL1_ASCAST:%.*]] = addrspacecast ptr [[SELECT_STR_TRIVIAL1]] to ptr addrspace(4)
31 // CHECK-NEXT: [[SELECT_STR_TRIVIAL2_ASCAST:%.*]] = addrspacecast ptr [[SELECT_STR_TRIVIAL2]] to ptr addrspace(4)
32 // CHECK-NEXT: store i32 0, ptr addrspace(4) [[I_ASCAST]], align 4
33 // CHECK-NEXT: store ptr addrspace(4) [[I_ASCAST]], ptr addrspace(4) [[PPTR_ASCAST]], align 8
34 // CHECK-NEXT: [[TMP0:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[PPTR_ASCAST]], align 8
35 // CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(4) [[TMP0]], [[I_ASCAST]]
36 // CHECK-NEXT: [[STOREDV:%.*]] = zext i1 [[CMP]] to i8
37 // CHECK-NEXT: store i8 [[STOREDV]], ptr addrspace(4) [[IS_I_PTR_ASCAST]], align 1
38 // CHECK-NEXT: [[TMP1:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[PPTR_ASCAST]], align 8
39 // CHECK-NEXT: store i32 66, ptr addrspace(4) [[TMP1]], align 4
40 // CHECK-NEXT: store i32 23, ptr addrspace(4) [[VAR23_ASCAST]], align 4
41 // CHECK-NEXT: store ptr addrspace(4) [[VAR23_ASCAST]], ptr addrspace(4) [[CP_ASCAST]], align 8
42 // CHECK-NEXT: [[TMP2:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[CP_ASCAST]], align 8
43 // CHECK-NEXT: store i8 41, ptr addrspace(4) [[TMP2]], align 1
44 // CHECK-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [42 x i32], ptr addrspace(4) [[ARR_ASCAST]], i64 0, i64 0
45 // CHECK-NEXT: store ptr addrspace(4) [[ARRAYDECAY]], ptr addrspace(4) [[CPP_ASCAST]], align 8
46 // CHECK-NEXT: [[TMP3:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[CPP_ASCAST]], align 8
47 // CHECK-NEXT: store i8 43, ptr addrspace(4) [[TMP3]], align 1
48 // CHECK-NEXT: [[ARRAYDECAY1:%.*]] = getelementptr inbounds [42 x i32], ptr addrspace(4) [[ARR_ASCAST]], i64 0, i64 0
49 // CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr addrspace(4) [[ARRAYDECAY1]], i64 10
50 // CHECK-NEXT: store ptr addrspace(4) [[ADD_PTR]], ptr addrspace(4) [[APTR_ASCAST]], align 8
51 // CHECK-NEXT: [[TMP4:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[APTR_ASCAST]], align 8
52 // CHECK-NEXT: [[ARRAYDECAY2:%.*]] = getelementptr inbounds [42 x i32], ptr addrspace(4) [[ARR_ASCAST]], i64 0, i64 0
53 // CHECK-NEXT: [[ADD_PTR3:%.*]] = getelementptr inbounds nuw i32, ptr addrspace(4) [[ARRAYDECAY2]], i64 168
54 // CHECK-NEXT: [[CMP4:%.*]] = icmp ult ptr addrspace(4) [[TMP4]], [[ADD_PTR3]]
55 // CHECK-NEXT: br i1 [[CMP4]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
56 // CHECK: if.then:
57 // CHECK-NEXT: [[TMP5:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[APTR_ASCAST]], align 8
58 // CHECK-NEXT: store i32 44, ptr addrspace(4) [[TMP5]], align 4
59 // CHECK-NEXT: br label [[IF_END]]
60 // CHECK: if.end:
61 // CHECK-NEXT: store ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str to ptr addrspace(4)), ptr addrspace(4) [[STR_ASCAST]], align 8
62 // CHECK-NEXT: [[TMP6:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[STR_ASCAST]], align 8
63 // CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr addrspace(4) [[TMP6]], i64 0
64 // CHECK-NEXT: [[TMP7:%.*]] = load i8, ptr addrspace(4) [[ARRAYIDX]], align 1
65 // CHECK-NEXT: [[CONV:%.*]] = sext i8 [[TMP7]] to i32
66 // CHECK-NEXT: store i32 [[CONV]], ptr addrspace(4) [[I_ASCAST]], align 4
67 // CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr addrspace(4) [[I_ASCAST]], align 4
68 // CHECK-NEXT: [[CMP5:%.*]] = icmp sgt i32 [[TMP8]], 2
69 // CHECK-NEXT: br i1 [[CMP5]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
70 // CHECK: cond.true:
71 // CHECK-NEXT: [[TMP9:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[STR_ASCAST]], align 8
72 // CHECK-NEXT: br label [[COND_END:%.*]]
73 // CHECK: cond.false:
74 // CHECK-NEXT: br label [[COND_END]]
75 // CHECK: cond.end:
76 // CHECK-NEXT: [[COND:%.*]] = phi ptr addrspace(4) [ [[TMP9]], [[COND_TRUE]] ], [ addrspacecast (ptr addrspace(1) @.str.1 to ptr addrspace(4)), [[COND_FALSE]] ]
77 // CHECK-NEXT: store ptr addrspace(4) [[COND]], ptr addrspace(4) [[PHI_STR_ASCAST]], align 8
78 // CHECK-NEXT: [[TMP10:%.*]] = load i32, ptr addrspace(4) [[I_ASCAST]], align 4
79 // CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[TMP10]], 2
80 // CHECK-NEXT: [[TMP11:%.*]] = zext i1 [[CMP6]] to i64
81 // CHECK-NEXT: [[COND7:%.*]] = select i1 [[CMP6]], ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str.2 to ptr addrspace(4)), ptr addrspace(4) null
82 // CHECK-NEXT: store ptr addrspace(4) [[COND7]], ptr addrspace(4) [[SELECT_NULL_ASCAST]], align 8
83 // CHECK-NEXT: [[TMP12:%.*]] = load ptr addrspace(4), ptr addrspace(4) [[STR_ASCAST]], align 8
84 // CHECK-NEXT: store ptr addrspace(4) [[TMP12]], ptr addrspace(4) [[SELECT_STR_TRIVIAL1_ASCAST]], align 8
85 // CHECK-NEXT: store ptr addrspace(4) addrspacecast (ptr addrspace(1) @.str.1 to ptr addrspace(4)), ptr addrspace(4) [[SELECT_STR_TRIVIAL2_ASCAST]], align 8
86 // CHECK-NEXT: ret void
88 void test() {
89 static const int foo = 0x42;
92 int i = 0;
93 int *pptr = &i;
94 bool is_i_ptr = (pptr == &i);
95 *pptr = foo;
97 int var23 = 23;
98 char *cp = (char *)&var23;
99 *cp = 41;
101 int arr[42];
102 char *cpp = (char *)arr;
103 *cpp = 43;
105 int *aptr = arr + 10;
106 if (aptr < arr + sizeof(arr))
107 *aptr = 44;
109 const char *str = "Hello, world!";
111 i = str[0];
113 const char *phi_str = i > 2 ? str : "Another hello world!";
114 (void)phi_str;
119 const char *select_null = i > 2 ? "Yet another Hello world" : nullptr;
120 (void)select_null;
122 const char *select_str_trivial1 = true ? str : "Another hello world!";
123 (void)select_str_trivial1;
125 const char *select_str_trivial2 = false ? str : "Another hello world!";
126 (void)select_str_trivial2;