1 ; RUN: opt < %s -ipsccp -S | FileCheck %s 2 3 ;;======================== test1 4 5 define internal i32 @test1a(i32 %A) { 6 %X = add i32 1, 2 7 ret i32 %A 8 } 9 ; CHECK-LABEL: define internal i32 @test1a( 10 ; CHECK: ret i32 undef 11 12 define i32 @test1b() { 13 %X = call i32 @test1a( i32 17 ) 14 ret i32 %X 15 16 ; CHECK-LABEL: define i32 @test1b( 17 ; CHECK: ret i32 17 18 } 19 20 21 22 ;;======================== test2 23 24 define internal i32 @test2a(i32 %A) { 25 %C = icmp eq i32 %A, 0 26 br i1 %C, label %T, label %F 27 T: 28 %B = call i32 @test2a( i32 0 ) 29 ret i32 0 30 F: 31 %C.upgrd.1 = call i32 @test2a(i32 1) 32 ret i32 %C.upgrd.1 33 } 34 ; CHECK-LABEL: define internal i32 @test2a( 35 ; CHECK-NEXT: br label %T 36 ; CHECK: ret i32 undef 37 38 39 define i32 @test2b() { 40 %X = call i32 @test2a(i32 0) 41 ret i32 %X 42 } 43 ; CHECK-LABEL: define i32 @test2b( 44 ; CHECK-NEXT: %X = call i32 @test2a(i32 0) 45 ; CHECK-NEXT: ret i32 0 46 47 48 ;;======================== test3 49 50 @G = internal global i32 undef 51 52 define void @test3a() { 53 %X = load i32, i32* @G 54 store i32 %X, i32* @G 55 ret void 56 } 57 ; CHECK-LABEL: define void @test3a( 58 ; CHECK-NEXT: ret void 59 60 61 define i32 @test3b() { 62 %V = load i32, i32* @G 63 %C = icmp eq i32 %V, 17 64 br i1 %C, label %T, label %F 65 T: 66 store i32 17, i32* @G 67 ret i32 %V 68 F: 69 store i32 123, i32* @G 70 ret i32 0 71 } 72 ; CHECK-LABEL: define i32 @test3b( 73 ; CHECK-NOT: store 74 ; CHECK: ret i32 0 75 76 77 ;;======================== test4 78 79 define internal {i64,i64} @test4a() { 80 %a = insertvalue {i64,i64} undef, i64 4, 1 81 %b = insertvalue {i64,i64} %a, i64 5, 0 82 ret {i64,i64} %b 83 } 84 85 ; CHECK-LABEL: define internal { i64, i64 } @test4a( 86 ; CHECK-NEXT: ret { i64, i64 } { i64 5, i64 4 } 87 ; CHECK-NEXT: } 88 89 define i64 @test4b() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 90 %a = invoke {i64,i64} @test4a() 91 to label %A unwind label %B 92 A: 93 %b = extractvalue {i64,i64} %a, 0 94 %c = call i64 @test4c(i64 %b) 95 ret i64 %c 96 B: 97 %val = landingpad { i8*, i32 } 98 catch i8* null 99 ret i64 0 100 } 101 ; CHECK: define i64 @test4b() 102 ; CHECK: %c = call i64 @test4c(i64 5) 103 ; CHECK-NEXT: ret i64 5 104 105 106 define internal i64 @test4c(i64 %a) { 107 ret i64 %a 108 } 109 ; CHECK-LABEL: define internal i64 @test4c( 110 ; CHECK: ret i64 undef 111 112 113 114 ;;======================== test5 115 116 ; PR4313 117 define internal {i64,i64} @test5a() { 118 %a = insertvalue {i64,i64} undef, i64 4, 1 119 %b = insertvalue {i64,i64} %a, i64 5, 0 120 ret {i64,i64} %b 121 } 122 123 define i64 @test5b() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 124 %a = invoke {i64,i64} @test5a() 125 to label %A unwind label %B 126 A: 127 %c = call i64 @test5c({i64,i64} %a) 128 ret i64 %c 129 B: 130 %val = landingpad { i8*, i32 } 131 catch i8* null 132 ret i64 0 133 } 134 135 ; CHECK: define i64 @test5b() 136 ; CHECK: A: 137 ; CHECK-NEXT: %c = call i64 @test5c({ i64, i64 } { i64 5, i64 4 }) 138 ; CHECK-NEXT: ret i64 5 139 140 define internal i64 @test5c({i64,i64} %a) { 141 %b = extractvalue {i64,i64} %a, 0 142 ret i64 %b 143 } 144 145 146 ;;======================== test6 147 148 define i64 @test6a() { 149 ret i64 0 150 } 151 152 define i64 @test6b() { 153 %a = call i64 @test6a() 154 ret i64 %a 155 } 156 ; CHECK-LABEL: define i64 @test6b( 157 ; CHECK: ret i64 0 158 159 ;;======================== test7 160 161 162 %T = type {i32,i32} 163 164 define internal %T @test7a(i32 %A) { 165 %X = add i32 1, %A 166 %mrv0 = insertvalue %T undef, i32 %X, 0 167 %mrv1 = insertvalue %T %mrv0, i32 %A, 1 168 ret %T %mrv1 169 ; CHECK-LABEL: @test7a( 170 ; CHECK-NEXT: ret %T { i32 18, i32 17 } 171 } 172 173 define i32 @test7b() { 174 %X = call %T @test7a(i32 17) 175 %Y = extractvalue %T %X, 0 176 %Z = add i32 %Y, %Y 177 ret i32 %Z 178 ; CHECK-LABEL: define i32 @test7b( 179 ; CHECK-NEXT: call %T @test7a(i32 17) 180 ; CHECK-NEXT: ret i32 36 181 } 182 183 ;;======================== test8 184 185 186 define internal {} @test8a(i32 %A, i32* %P) { 187 store i32 %A, i32* %P 188 ret {} {} 189 ; CHECK-LABEL: @test8a( 190 ; CHECK-NEXT: store i32 5, 191 ; CHECK-NEXT: ret 192 } 193 194 define void @test8b(i32* %P) { 195 %X = call {} @test8a(i32 5, i32* %P) 196 ret void 197 ; CHECK-LABEL: define void @test8b( 198 ; CHECK-NEXT: call {} @test8a 199 ; CHECK-NEXT: ret void 200 } 201 202 ;;======================== test9 203 204 @test9g = internal global { } zeroinitializer 205 206 define void @test9() { 207 entry: 208 %local_foo = alloca { } 209 load { }, { }* @test9g 210 store { } %0, { }* %local_foo 211 ret void 212 } 213 214 ; CHECK-LABEL: define void @test9( 215 ; CHECK-NEXT: entry: 216 ; CHECK-NEXT: %local_foo = alloca {} 217 ; CHECK-NEXT: store {} zeroinitializer, {}* %local_foo 218 ; CHECK-NEXT: ret void 219 220 declare i32 @__gxx_personality_v0(...) 221 222 ;;======================== test10 223 224 define i32 @test10a() nounwind { 225 entry: 226 %call = call i32 @test10b(i32 undef) 227 ret i32 %call 228 ; CHECK-LABEL: define i32 @test10a( 229 ; CHECK: ret i32 0 230 } 231 232 define internal i32 @test10b(i32 %x) nounwind { 233 entry: 234 %r = and i32 %x, 1 235 ret i32 %r 236 ; CHECK-LABEL: define internal i32 @test10b( 237 ; CHECK: ret i32 undef 238 } 239 240 ;;======================== test11 241 242 define i64 @test11a() { 243 %xor = xor i64 undef, undef 244 ret i64 %xor 245 ; CHECK-LABEL: define i64 @test11a 246 ; CHECK: ret i64 0 247 } 248 249 define void @test11b() { 250 %call1 = call i64 @test11a() 251 %call2 = call i64 @llvm.ctpop.i64(i64 %call1) 252 ret void 253 ; CHECK-LABEL: define void @test11b 254 ; CHECK: %[[call1:.*]] = call i64 @test11a() 255 ; CHECK: %[[call2:.*]] = call i64 @llvm.ctpop.i64(i64 0) 256 } 257 258 declare i64 @llvm.ctpop.i64(i64) 259