1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 define ptr @bitcast_opaque_to_opaque(ptr %a) {
5 ; CHECK-LABEL: @bitcast_opaque_to_opaque(
6 ; CHECK-NEXT: ret ptr [[A:%.*]]
8 %b = bitcast ptr %a to ptr
12 define ptr @bitcast_typed_to_opaque(i8* %a) {
13 ; CHECK-LABEL: @bitcast_typed_to_opaque(
14 ; CHECK-NEXT: [[B:%.*]] = bitcast i8* [[A:%.*]] to ptr
15 ; CHECK-NEXT: ret ptr [[B]]
17 %b = bitcast i8* %a to ptr
21 define i8* @bitcast_opaque_to_typed(ptr %a) {
22 ; CHECK-LABEL: @bitcast_opaque_to_typed(
23 ; CHECK-NEXT: [[B:%.*]] = bitcast ptr [[A:%.*]] to i8*
24 ; CHECK-NEXT: ret i8* [[B]]
26 %b = bitcast ptr %a to i8*
31 define ptr @bitcast_typed_to_opaque_constexpr() {
32 ; CHECK-LABEL: @bitcast_typed_to_opaque_constexpr(
33 ; CHECK-NEXT: ret ptr bitcast (i8* @g to ptr)
35 ret ptr bitcast (i8* @g to ptr)
38 define ptr @addrspacecast_opaque_to_opaque(ptr addrspace(1) %a) {
39 ; CHECK-LABEL: @addrspacecast_opaque_to_opaque(
40 ; CHECK-NEXT: [[B:%.*]] = addrspacecast ptr addrspace(1) [[A:%.*]] to ptr
41 ; CHECK-NEXT: ret ptr [[B]]
43 %b = addrspacecast ptr addrspace(1) %a to ptr
47 define ptr @addrspacecast_typed_to_opaque(i8 addrspace(1)* %a) {
48 ; CHECK-LABEL: @addrspacecast_typed_to_opaque(
49 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8 addrspace(1)* [[A:%.*]] to ptr addrspace(1)
50 ; CHECK-NEXT: [[B:%.*]] = addrspacecast ptr addrspace(1) [[TMP1]] to ptr
51 ; CHECK-NEXT: ret ptr [[B]]
53 %b = addrspacecast i8 addrspace(1)* %a to ptr
57 define i8* @addrspacecast_opaque_to_typed(ptr addrspace(1) %a) {
58 ; CHECK-LABEL: @addrspacecast_opaque_to_typed(
59 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast ptr addrspace(1) [[A:%.*]] to i8 addrspace(1)*
60 ; CHECK-NEXT: [[B:%.*]] = addrspacecast i8 addrspace(1)* [[TMP1]] to i8*
61 ; CHECK-NEXT: ret i8* [[B]]
63 %b = addrspacecast ptr addrspace(1) %a to i8*
67 define ptr addrspace(1) @bitcast_and_addrspacecast_eliminable(ptr %a) {
68 ; CHECK-LABEL: @bitcast_and_addrspacecast_eliminable(
69 ; CHECK-NEXT: [[C:%.*]] = addrspacecast ptr [[A:%.*]] to ptr addrspace(1)
70 ; CHECK-NEXT: ret ptr addrspace(1) [[C]]
72 %b = bitcast ptr %a to i8*
73 %c = addrspacecast i8* %b to ptr addrspace(1)
74 ret ptr addrspace(1) %c
77 define ptr addrspace(1) @addrspacecast_typed_to_opaque_constexpr() {
78 ; CHECK-LABEL: @addrspacecast_typed_to_opaque_constexpr(
79 ; CHECK-NEXT: ret ptr addrspace(1) addrspacecast (ptr bitcast (i8* @g to ptr) to ptr addrspace(1))
81 ret ptr addrspace(1) addrspacecast (i8* @g to ptr addrspace(1))
84 define ptr @gep_constexpr_1(ptr %a) {
85 ; CHECK-LABEL: @gep_constexpr_1(
86 ; CHECK-NEXT: ret ptr inttoptr (i64 6 to ptr)
88 ret ptr getelementptr (i16, ptr null, i32 3)
91 define ptr @gep_constexpr_2(ptr %a) {
92 ; CHECK-LABEL: @gep_constexpr_2(
93 ; CHECK-NEXT: ret ptr bitcast (i8* getelementptr (i8, i8* @g, i64 3) to ptr)
95 ret ptr getelementptr (i8, ptr bitcast (i8* @g to ptr), i32 3)
98 define ptr @load_bitcast_1(ptr %a) {
99 ; CHECK-LABEL: @load_bitcast_1(
100 ; CHECK-NEXT: [[B1:%.*]] = load ptr, ptr [[A:%.*]], align 8
101 ; CHECK-NEXT: ret ptr [[B1]]
103 %b = load i8*, ptr %a
104 %c = bitcast i8* %b to ptr
108 define ptr @load_bitcast_2(ptr %a) {
109 ; CHECK-LABEL: @load_bitcast_2(
110 ; CHECK-NEXT: [[C1:%.*]] = load ptr, ptr [[A:%.*]], align 8
111 ; CHECK-NEXT: ret ptr [[C1]]
113 %b = bitcast ptr %a to i8**
114 %c = load i8*, i8** %b
115 %d = bitcast i8* %c to ptr
119 define void @call(ptr %a) {
120 ; CHECK-LABEL: @call(
121 ; CHECK-NEXT: call void [[A:%.*]]()
122 ; CHECK-NEXT: ret void
128 declare void @varargs(...)
129 define void @varargs_cast_typed_to_opaque_same_type(i32* %a) {
130 ; CHECK-LABEL: @varargs_cast_typed_to_opaque_same_type(
131 ; CHECK-NEXT: call void (...) @varargs(i32* byval(i32) [[A:%.*]])
132 ; CHECK-NEXT: ret void
134 %b = bitcast i32* %a to ptr
135 call void (...) @varargs(ptr byval(i32) %b)
139 define void @varargs_cast_typed_to_opaque_different_type(i32* %a) {
140 ; CHECK-LABEL: @varargs_cast_typed_to_opaque_different_type(
141 ; CHECK-NEXT: call void (...) @varargs(i32* byval(i32) [[A:%.*]])
142 ; CHECK-NEXT: ret void
144 %b = bitcast i32* %a to ptr
145 call void (...) @varargs(ptr byval(float) %b)
149 define void @varargs_cast_typed_to_opaque_different_size(i32* %a) {
150 ; CHECK-LABEL: @varargs_cast_typed_to_opaque_different_size(
151 ; CHECK-NEXT: [[B:%.*]] = bitcast i32* [[A:%.*]] to ptr
152 ; CHECK-NEXT: call void (...) @varargs(ptr byval(i64) [[B]])
153 ; CHECK-NEXT: ret void
155 %b = bitcast i32* %a to ptr
156 call void (...) @varargs(ptr byval(i64) %b)
160 define void @varargs_cast_opaque_to_typed(ptr %a) {
161 ; CHECK-LABEL: @varargs_cast_opaque_to_typed(
162 ; CHECK-NEXT: call void (...) @varargs(ptr byval(i8) [[A:%.*]])
163 ; CHECK-NEXT: ret void
165 %b = bitcast ptr %a to i8*
166 call void (...) @varargs(i8* byval(i8) %b)