1 ; RUN: opt -instcombine -early-cse -S < %s | FileCheck %s
4 ; CHECK-LABEL: define i8* @simplifyNullLaunder()
5 define i8* @simplifyNullLaunder() {
6 ; CHECK-NEXT: ret i8* null
7 %b2 = call i8* @llvm.launder.invariant.group.p0i8(i8* null)
11 ; CHECK-LABEL: define i8* @dontSimplifyNullLaunderNoNullOpt()
12 define i8* @dontSimplifyNullLaunderNoNullOpt() #0 {
13 ; CHECK-NEXT: call i8* @llvm.launder.invariant.group.p0i8(i8* null)
14 %b2 = call i8* @llvm.launder.invariant.group.p0i8(i8* null)
18 ; CHECK-LABEL: define i8 addrspace(42)* @dontsimplifyNullLaunderForDifferentAddrspace()
19 define i8 addrspace(42)* @dontsimplifyNullLaunderForDifferentAddrspace() {
20 ; CHECK: %b2 = call i8 addrspace(42)* @llvm.launder.invariant.group.p42i8(i8 addrspace(42)* null)
21 ; CHECK: ret i8 addrspace(42)* %b2
22 %b2 = call i8 addrspace(42)* @llvm.launder.invariant.group.p42i8(i8 addrspace(42)* null)
23 ret i8 addrspace(42)* %b2
26 ; CHECK-LABEL: define i8* @simplifyUndefLaunder()
27 define i8* @simplifyUndefLaunder() {
28 ; CHECK-NEXT: ret i8* undef
29 %b2 = call i8* @llvm.launder.invariant.group.p0i8(i8* undef)
33 ; CHECK-LABEL: define i8 addrspace(42)* @simplifyUndefLaunder2()
34 define i8 addrspace(42)* @simplifyUndefLaunder2() {
35 ; CHECK-NEXT: ret i8 addrspace(42)* undef
36 %b2 = call i8 addrspace(42)* @llvm.launder.invariant.group.p42i8(i8 addrspace(42)* undef)
37 ret i8 addrspace(42)* %b2
40 ; CHECK-LABEL: define i8* @simplifyNullStrip()
41 define i8* @simplifyNullStrip() {
42 ; CHECK-NEXT: ret i8* null
43 %b2 = call i8* @llvm.strip.invariant.group.p0i8(i8* null)
47 ; CHECK-LABEL: define i8* @dontSimplifyNullStripNonNullOpt()
48 define i8* @dontSimplifyNullStripNonNullOpt() #0 {
49 ; CHECK-NEXT: call i8* @llvm.strip.invariant.group.p0i8(i8* null)
50 %b2 = call i8* @llvm.strip.invariant.group.p0i8(i8* null)
54 ; CHECK-LABEL: define i8 addrspace(42)* @dontsimplifyNullStripForDifferentAddrspace()
55 define i8 addrspace(42)* @dontsimplifyNullStripForDifferentAddrspace() {
56 ; CHECK: %b2 = call i8 addrspace(42)* @llvm.strip.invariant.group.p42i8(i8 addrspace(42)* null)
57 ; CHECK: ret i8 addrspace(42)* %b2
58 %b2 = call i8 addrspace(42)* @llvm.strip.invariant.group.p42i8(i8 addrspace(42)* null)
59 ret i8 addrspace(42)* %b2
62 ; CHECK-LABEL: define i8* @simplifyUndefStrip()
63 define i8* @simplifyUndefStrip() {
64 ; CHECK-NEXT: ret i8* undef
65 %b2 = call i8* @llvm.strip.invariant.group.p0i8(i8* undef)
69 ; CHECK-LABEL: define i8 addrspace(42)* @simplifyUndefStrip2()
70 define i8 addrspace(42)* @simplifyUndefStrip2() {
71 ; CHECK-NEXT: ret i8 addrspace(42)* undef
72 %b2 = call i8 addrspace(42)* @llvm.strip.invariant.group.p42i8(i8 addrspace(42)* undef)
73 ret i8 addrspace(42)* %b2
76 ; CHECK-LABEL: define i8* @simplifyLaunderOfLaunder(
77 define i8* @simplifyLaunderOfLaunder(i8* %a) {
78 ; CHECK: call i8* @llvm.launder.invariant.group.p0i8(i8* %a)
79 ; CHECK-NOT: llvm.launder.invariant.group
80 %a2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %a)
81 %a3 = call i8* @llvm.launder.invariant.group.p0i8(i8* %a2)
85 ; CHECK-LABEL: define i8* @simplifyStripOfLaunder(
86 define i8* @simplifyStripOfLaunder(i8* %a) {
87 ; CHECK-NOT: llvm.launder.invariant.group
88 ; CHECK: call i8* @llvm.strip.invariant.group.p0i8(i8* %a)
89 %a2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %a)
90 %a3 = call i8* @llvm.strip.invariant.group.p0i8(i8* %a2)
94 ; CHECK-LABEL: define i1 @simplifyForCompare(
95 define i1 @simplifyForCompare(i8* %a) {
96 %a2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %a)
98 %a3 = call i8* @llvm.strip.invariant.group.p0i8(i8* %a2)
99 %b2 = call i8* @llvm.strip.invariant.group.p0i8(i8* %a)
100 %c = icmp eq i8* %a3, %b2
105 ; CHECK-LABEL: define i16* @skipWithDifferentTypes(
106 define i16* @skipWithDifferentTypes(i8* %a) {
107 %a2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %a)
108 %c1 = bitcast i8* %a2 to i16*
110 ; CHECK: %[[b:.*]] = call i8* @llvm.strip.invariant.group.p0i8(i8* %a)
111 %a3 = call i16* @llvm.strip.invariant.group.p0i16(i16* %c1)
112 ; CHECK-NEXT: %[[r:.*]] = bitcast i8* %[[b]] to i16*
113 ; CHECK-NEXT: ret i16* %[[r]]
117 ; CHECK-LABEL: define i16 addrspace(42)* @skipWithDifferentTypesAddrspace(
118 define i16 addrspace(42)* @skipWithDifferentTypesAddrspace(i8 addrspace(42)* %a) {
119 %a2 = call i8 addrspace(42)* @llvm.launder.invariant.group.p42i8(i8 addrspace(42)* %a)
120 %c1 = bitcast i8 addrspace(42)* %a2 to i16 addrspace(42)*
122 ; CHECK: %[[b:.*]] = call i8 addrspace(42)* @llvm.strip.invariant.group.p42i8(i8 addrspace(42)* %a)
123 %a3 = call i16 addrspace(42)* @llvm.strip.invariant.group.p42i16(i16 addrspace(42)* %c1)
124 ; CHECK-NEXT: %[[r:.*]] = bitcast i8 addrspace(42)* %[[b]] to i16 addrspace(42)*
125 ; CHECK-NEXT: ret i16 addrspace(42)* %[[r]]
126 ret i16 addrspace(42)* %a3
129 ; CHECK-LABEL: define i16 addrspace(42)* @skipWithDifferentTypesDifferentAddrspace(
130 define i16 addrspace(42)* @skipWithDifferentTypesDifferentAddrspace(i8* %a) {
131 %cast = addrspacecast i8* %a to i8 addrspace(42)*
132 %a2 = call i8 addrspace(42)* @llvm.launder.invariant.group.p42i8(i8 addrspace(42)* %cast)
133 %c1 = bitcast i8 addrspace(42)* %a2 to i16 addrspace(42)*
135 ; CHECK: %[[b:.*]] = call i8* @llvm.strip.invariant.group.p0i8(i8* %a)
136 %a3 = call i16 addrspace(42)* @llvm.strip.invariant.group.p42i16(i16 addrspace(42)* %c1)
137 ; CHECK-NEXT: %[[r:.*]] = bitcast i8* %[[b]] to i16*
138 ; CHECK-NEXT: %[[r2:.*]] = addrspacecast i16* %[[r]] to i16 addrspace(42)*
139 ; CHECK-NEXT: ret i16 addrspace(42)* %[[r2]]
140 ret i16 addrspace(42)* %a3
143 declare i8* @llvm.launder.invariant.group.p0i8(i8*)
144 declare i8 addrspace(42)* @llvm.launder.invariant.group.p42i8(i8 addrspace(42)*)
145 declare i8* @llvm.strip.invariant.group.p0i8(i8*)
146 declare i8 addrspace(42)* @llvm.strip.invariant.group.p42i8(i8 addrspace(42)*)
147 declare i16* @llvm.strip.invariant.group.p0i16(i16* %c1)
148 declare i16 addrspace(42)* @llvm.strip.invariant.group.p42i16(i16 addrspace(42)* %c1)
150 attributes #0 = { "null-pointer-is-valid"="true" }