1; RUN: opt -S -passes='bdce,instsimplify' < %s | FileCheck %s 2; RUN: opt -S -passes=instsimplify < %s | FileCheck %s -check-prefix=CHECK-IO 3; RUN: opt -S -passes='debugify,bdce' < %s | FileCheck %s -check-prefix=DEBUGIFY 4; RUN: opt -S -passes='debugify,bdce' < %s --try-experimental-debuginfo-iterators | FileCheck %s -check-prefix=DEBUGIFY 5target datalayout = "E-m:e-i64:64-n32:64" 6target triple = "powerpc64-unknown-linux-gnu" 7 8; Function Attrs: nounwind readnone 9define signext i32 @bar(i32 signext %x) #0 { 10entry: 11 %call = tail call signext i32 @foo(i32 signext 5) #0 12 %and = and i32 %call, 4 13 %or = or i32 %and, %x 14 %call1 = tail call signext i32 @foo(i32 signext 3) #0 15 %and2 = and i32 %call1, 8 16 %or3 = or i32 %or, %and2 17 %call4 = tail call signext i32 @foo(i32 signext 2) #0 18 %and5 = and i32 %call4, 16 19 %or6 = or i32 %or3, %and5 20 %call7 = tail call signext i32 @foo(i32 signext 1) #0 21 %and8 = and i32 %call7, 32 22 %or9 = or i32 %or6, %and8 23 %call10 = tail call signext i32 @foo(i32 signext 0) #0 24 %and11 = and i32 %call10, 64 25 %or12 = or i32 %or9, %and11 26 %call13 = tail call signext i32 @foo(i32 signext 4) #0 27 %and14 = and i32 %call13, 128 28 %or15 = or i32 %or12, %and14 29 %shr = ashr i32 %or15, 4 30 ret i32 %shr 31 32; CHECK-LABEL: @bar 33; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 34; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 35; CHECK: tail call signext i32 @foo(i32 signext 2) 36; CHECK: tail call signext i32 @foo(i32 signext 1) 37; CHECK: tail call signext i32 @foo(i32 signext 0) 38; CHECK: tail call signext i32 @foo(i32 signext 4) 39; CHECK: ret i32 40 41; Check that instsimplify is not doing this all on its own. 42; CHECK-IO-LABEL: @bar 43; CHECK-IO: tail call signext i32 @foo(i32 signext 5) 44; CHECK-IO: tail call signext i32 @foo(i32 signext 3) 45; CHECK-IO: tail call signext i32 @foo(i32 signext 2) 46; CHECK-IO: tail call signext i32 @foo(i32 signext 1) 47; CHECK-IO: tail call signext i32 @foo(i32 signext 0) 48; CHECK-IO: tail call signext i32 @foo(i32 signext 4) 49; CHECK-IO: ret i32 50} 51 52; Function Attrs: nounwind readnone 53declare signext i32 @foo(i32 signext) #0 54 55; Function Attrs: nounwind readnone 56define signext i32 @far(i32 signext %x) #1 { 57entry: 58 %call = tail call signext i32 @goo(i32 signext 5) #1 59 %and = and i32 %call, 4 60 %or = or i32 %and, %x 61 %call1 = tail call signext i32 @goo(i32 signext 3) #1 62 %and2 = and i32 %call1, 8 63 %or3 = or i32 %or, %and2 64 %call4 = tail call signext i32 @goo(i32 signext 2) #1 65 %and5 = and i32 %call4, 16 66 %or6 = or i32 %or3, %and5 67 %call7 = tail call signext i32 @goo(i32 signext 1) #1 68 %and8 = and i32 %call7, 32 69 %or9 = or i32 %or6, %and8 70 %call10 = tail call signext i32 @goo(i32 signext 0) #1 71 %and11 = and i32 %call10, 64 72 %or12 = or i32 %or9, %and11 73 %call13 = tail call signext i32 @goo(i32 signext 4) #1 74 %and14 = and i32 %call13, 128 75 %or15 = or i32 %or12, %and14 76 %shr = ashr i32 %or15, 4 77 ret i32 %shr 78 79; CHECK-LABEL: @far 80; Calls to foo(5) and foo(3) are still there, but their results are not used. 81; CHECK: tail call signext i32 @goo(i32 signext 5) 82; CHECK-NEXT: tail call signext i32 @goo(i32 signext 3) 83; CHECK-NEXT: tail call signext i32 @goo(i32 signext 2) 84; CHECK: tail call signext i32 @goo(i32 signext 1) 85; CHECK: tail call signext i32 @goo(i32 signext 0) 86; CHECK: tail call signext i32 @goo(i32 signext 4) 87; CHECK: ret i32 88 89; Check that instsimplify is not doing this all on its own. 90; CHECK-IO-LABEL: @far 91; CHECK-IO: tail call signext i32 @goo(i32 signext 5) 92; CHECK-IO: tail call signext i32 @goo(i32 signext 3) 93; CHECK-IO: tail call signext i32 @goo(i32 signext 2) 94; CHECK-IO: tail call signext i32 @goo(i32 signext 1) 95; CHECK-IO: tail call signext i32 @goo(i32 signext 0) 96; CHECK-IO: tail call signext i32 @goo(i32 signext 4) 97; CHECK-IO: ret i32 98} 99 100declare signext i32 @goo(i32 signext) #1 101 102; Function Attrs: nounwind readnone 103define signext i32 @tar1(i32 signext %x) #0 { 104entry: 105 %call = tail call signext i32 @foo(i32 signext 5) #0 106 %and = and i32 %call, 33554432 107 %or = or i32 %and, %x 108 %call1 = tail call signext i32 @foo(i32 signext 3) #0 109 %and2 = and i32 %call1, 67108864 110 %or3 = or i32 %or, %and2 111 %call4 = tail call signext i32 @foo(i32 signext 2) #0 112 %and5 = and i32 %call4, 16 113 %or6 = or i32 %or3, %and5 114 %call7 = tail call signext i32 @foo(i32 signext 1) #0 115 %and8 = and i32 %call7, 32 116 %or9 = or i32 %or6, %and8 117 %call10 = tail call signext i32 @foo(i32 signext 0) #0 118 %and11 = and i32 %call10, 64 119 %or12 = or i32 %or9, %and11 120 %call13 = tail call signext i32 @foo(i32 signext 4) #0 121 %and14 = and i32 %call13, 128 122 %or15 = or i32 %or12, %and14 123 %bs = tail call i32 @llvm.bswap.i32(i32 %or15) #0 124 %shr = ashr i32 %bs, 4 125 ret i32 %shr 126 127; CHECK-LABEL: @tar1 128; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 129; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 130; CHECK: tail call signext i32 @foo(i32 signext 2) 131; CHECK: tail call signext i32 @foo(i32 signext 1) 132; CHECK: tail call signext i32 @foo(i32 signext 0) 133; CHECK: tail call signext i32 @foo(i32 signext 4) 134; CHECK: ret i32 135} 136 137; Function Attrs: nounwind readnone 138declare i32 @llvm.bswap.i32(i32) #0 139 140; Function Attrs: nounwind readnone 141define signext i32 @tim(i32 signext %x) #0 { 142entry: 143 %call = tail call signext i32 @foo(i32 signext 5) #0 144 %and = and i32 %call, 536870912 145 %or = or i32 %and, %x 146 %call1 = tail call signext i32 @foo(i32 signext 3) #0 147 %and2 = and i32 %call1, 1073741824 148 %or3 = or i32 %or, %and2 149 %call4 = tail call signext i32 @foo(i32 signext 2) #0 150 %and5 = and i32 %call4, 16 151 %or6 = or i32 %or3, %and5 152 %call7 = tail call signext i32 @foo(i32 signext 1) #0 153 %and8 = and i32 %call7, 32 154 %or9 = or i32 %or6, %and8 155 %call10 = tail call signext i32 @foo(i32 signext 0) #0 156 %and11 = and i32 %call10, 64 157 %or12 = or i32 %or9, %and11 158 %call13 = tail call signext i32 @foo(i32 signext 4) #0 159 %and14 = and i32 %call13, 128 160 %or15 = or i32 %or12, %and14 161 %bs = tail call i32 @llvm.bitreverse.i32(i32 %or15) #0 162 %shr = ashr i32 %bs, 4 163 ret i32 %shr 164 165; CHECK-LABEL: @tim 166; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 167; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 168; CHECK: tail call signext i32 @foo(i32 signext 2) 169; CHECK: tail call signext i32 @foo(i32 signext 1) 170; CHECK: tail call signext i32 @foo(i32 signext 0) 171; CHECK: tail call signext i32 @foo(i32 signext 4) 172; CHECK: ret i32 173} 174 175; Function Attrs: nounwind readnone 176declare i32 @llvm.bitreverse.i32(i32) #0 177 178; Function Attrs: nounwind readnone 179define signext i32 @tar2(i32 signext %x) #0 { 180entry: 181 %call = tail call signext i32 @foo(i32 signext 5) #0 182 %and = and i32 %call, 33554432 183 %or = or i32 %and, %x 184 %call1 = tail call signext i32 @foo(i32 signext 3) #0 185 %and2 = and i32 %call1, 67108864 186 %or3 = or i32 %or, %and2 187 %call4 = tail call signext i32 @foo(i32 signext 2) #0 188 %and5 = and i32 %call4, 16 189 %or6 = or i32 %or3, %and5 190 %call7 = tail call signext i32 @foo(i32 signext 1) #0 191 %and8 = and i32 %call7, 32 192 %or9 = or i32 %or6, %and8 193 %call10 = tail call signext i32 @foo(i32 signext 0) #0 194 %and11 = and i32 %call10, 64 195 %or12 = or i32 %or9, %and11 196 %call13 = tail call signext i32 @foo(i32 signext 4) #0 197 %and14 = and i32 %call13, 128 198 %or15 = or i32 %or12, %and14 199 %shl = shl i32 %or15, 10 200 ret i32 %shl 201 202; CHECK-LABEL: @tar2 203; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 204; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 205; CHECK: tail call signext i32 @foo(i32 signext 2) 206; CHECK: tail call signext i32 @foo(i32 signext 1) 207; CHECK: tail call signext i32 @foo(i32 signext 0) 208; CHECK: tail call signext i32 @foo(i32 signext 4) 209; CHECK: ret i32 210} 211 212; Function Attrs: nounwind readnone 213define signext i32 @tar3(i32 signext %x) #0 { 214entry: 215 %call = tail call signext i32 @foo(i32 signext 5) #0 216 %and = and i32 %call, 33554432 217 %or = or i32 %and, %x 218 %call1 = tail call signext i32 @foo(i32 signext 3) #0 219 %and2 = and i32 %call1, 67108864 220 %or3 = or i32 %or, %and2 221 %call4 = tail call signext i32 @foo(i32 signext 2) #0 222 %and5 = and i32 %call4, 16 223 %or6 = or i32 %or3, %and5 224 %call7 = tail call signext i32 @foo(i32 signext 1) #0 225 %and8 = and i32 %call7, 32 226 %or9 = or i32 %or6, %and8 227 %call10 = tail call signext i32 @foo(i32 signext 0) #0 228 %and11 = and i32 %call10, 64 229 %or12 = or i32 %or9, %and11 230 %call13 = tail call signext i32 @foo(i32 signext 4) #0 231 %and14 = and i32 %call13, 128 232 %or15 = or i32 %or12, %and14 233 %add = add i32 %or15, 5 234 %shl = shl i32 %add, 10 235 ret i32 %shl 236 237; CHECK-LABEL: @tar3 238; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 239; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 240; CHECK: tail call signext i32 @foo(i32 signext 2) 241; CHECK: tail call signext i32 @foo(i32 signext 1) 242; CHECK: tail call signext i32 @foo(i32 signext 0) 243; CHECK: tail call signext i32 @foo(i32 signext 4) 244; CHECK: ret i32 245} 246 247; Function Attrs: nounwind readnone 248define signext i32 @tar4(i32 signext %x) #0 { 249entry: 250 %call = tail call signext i32 @foo(i32 signext 5) #0 251 %and = and i32 %call, 33554432 252 %or = or i32 %and, %x 253 %call1 = tail call signext i32 @foo(i32 signext 3) #0 254 %and2 = and i32 %call1, 67108864 255 %or3 = or i32 %or, %and2 256 %call4 = tail call signext i32 @foo(i32 signext 2) #0 257 %and5 = and i32 %call4, 16 258 %or6 = or i32 %or3, %and5 259 %call7 = tail call signext i32 @foo(i32 signext 1) #0 260 %and8 = and i32 %call7, 32 261 %or9 = or i32 %or6, %and8 262 %call10 = tail call signext i32 @foo(i32 signext 0) #0 263 %and11 = and i32 %call10, 64 264 %or12 = or i32 %or9, %and11 265 %call13 = tail call signext i32 @foo(i32 signext 4) #0 266 %and14 = and i32 %call13, 128 267 %or15 = or i32 %or12, %and14 268 %sub = sub i32 %or15, 5 269 %shl = shl i32 %sub, 10 270 ret i32 %shl 271 272; CHECK-LABEL: @tar4 273; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 274; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 275; CHECK: tail call signext i32 @foo(i32 signext 2) 276; CHECK: tail call signext i32 @foo(i32 signext 1) 277; CHECK: tail call signext i32 @foo(i32 signext 0) 278; CHECK: tail call signext i32 @foo(i32 signext 4) 279; CHECK: ret i32 280} 281 282; Function Attrs: nounwind readnone 283define signext i32 @tar5(i32 signext %x) #0 { 284entry: 285 %call = tail call signext i32 @foo(i32 signext 5) #0 286 %and = and i32 %call, 33554432 287 %or = or i32 %and, %x 288 %call1 = tail call signext i32 @foo(i32 signext 3) #0 289 %and2 = and i32 %call1, 67108864 290 %or3 = or i32 %or, %and2 291 %call4 = tail call signext i32 @foo(i32 signext 2) #0 292 %and5 = and i32 %call4, 16 293 %or6 = or i32 %or3, %and5 294 %call7 = tail call signext i32 @foo(i32 signext 1) #0 295 %and8 = and i32 %call7, 32 296 %or9 = or i32 %or6, %and8 297 %call10 = tail call signext i32 @foo(i32 signext 0) #0 298 %and11 = and i32 %call10, 64 299 %or12 = or i32 %or9, %and11 300 %call13 = tail call signext i32 @foo(i32 signext 4) #0 301 %and14 = and i32 %call13, 128 302 %or15 = or i32 %or12, %and14 303 %xor = xor i32 %or15, 5 304 %shl = shl i32 %xor, 10 305 ret i32 %shl 306 307; CHECK-LABEL: @tar5 308; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 309; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 310; CHECK: tail call signext i32 @foo(i32 signext 2) 311; CHECK: tail call signext i32 @foo(i32 signext 1) 312; CHECK: tail call signext i32 @foo(i32 signext 0) 313; CHECK: tail call signext i32 @foo(i32 signext 4) 314; CHECK: ret i32 315} 316 317; Function Attrs: nounwind readnone 318define signext i32 @tar7(i32 signext %x, i1 %b) #0 { 319entry: 320 %call = tail call signext i32 @foo(i32 signext 5) #0 321 %and = and i32 %call, 33554432 322 %or = or i32 %and, %x 323 %call1 = tail call signext i32 @foo(i32 signext 3) #0 324 %and2 = and i32 %call1, 67108864 325 %or3 = or i32 %or, %and2 326 %call4 = tail call signext i32 @foo(i32 signext 2) #0 327 %and5 = and i32 %call4, 16 328 %or6 = or i32 %or3, %and5 329 %call7 = tail call signext i32 @foo(i32 signext 1) #0 330 %and8 = and i32 %call7, 32 331 %or9 = or i32 %or6, %and8 332 %call10 = tail call signext i32 @foo(i32 signext 0) #0 333 %and11 = and i32 %call10, 64 334 %or12 = or i32 %or9, %and11 335 %call13 = tail call signext i32 @foo(i32 signext 4) #0 336 %and14 = and i32 %call13, 128 337 %or15 = or i32 %or12, %and14 338 %v = select i1 %b, i32 %or15, i32 5 339 %shl = shl i32 %v, 10 340 ret i32 %shl 341 342; CHECK-LABEL: @tar7 343; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 344; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 345; CHECK: tail call signext i32 @foo(i32 signext 2) 346; CHECK: tail call signext i32 @foo(i32 signext 1) 347; CHECK: tail call signext i32 @foo(i32 signext 0) 348; CHECK: tail call signext i32 @foo(i32 signext 4) 349; CHECK: ret i32 350} 351 352; Function Attrs: nounwind readnone 353define signext i16 @tar8(i32 signext %x) #0 { 354entry: 355 %call = tail call signext i32 @foo(i32 signext 5) #0 356 %and = and i32 %call, 33554432 357 %or = or i32 %and, %x 358 %call1 = tail call signext i32 @foo(i32 signext 3) #0 359 %and2 = and i32 %call1, 67108864 360 %or3 = or i32 %or, %and2 361 %call4 = tail call signext i32 @foo(i32 signext 2) #0 362 %and5 = and i32 %call4, 16 363 %or6 = or i32 %or3, %and5 364 %call7 = tail call signext i32 @foo(i32 signext 1) #0 365 %and8 = and i32 %call7, 32 366 %or9 = or i32 %or6, %and8 367 %call10 = tail call signext i32 @foo(i32 signext 0) #0 368 %and11 = and i32 %call10, 64 369 %or12 = or i32 %or9, %and11 370 %call13 = tail call signext i32 @foo(i32 signext 4) #0 371 %and14 = and i32 %call13, 128 372 %or15 = or i32 %or12, %and14 373 %tr = trunc i32 %or15 to i16 374 ret i16 %tr 375 376; CHECK-LABEL: @tar8 377; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 378; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 379; CHECK: tail call signext i32 @foo(i32 signext 2) 380; CHECK: tail call signext i32 @foo(i32 signext 1) 381; CHECK: tail call signext i32 @foo(i32 signext 0) 382; CHECK: tail call signext i32 @foo(i32 signext 4) 383; CHECK: ret i16 384} 385 386; DEBUGIFY-LABEL: @tar9 387define signext i16 @tar9(i32 signext %x) #0 { 388entry: 389 %call = tail call signext i32 @foo(i32 signext 5) #0 390 %and = and i32 %call, 33554432 391; DEBUGIFY: #dbg_value(i32 %call, {{.*}}, !DIExpression(DW_OP_constu, 33554432, DW_OP_and, DW_OP_stack_value), 392 %cast = trunc i32 %call to i16 393 ret i16 %cast 394} 395 396attributes #0 = { nounwind readnone willreturn } 397attributes #1 = { nounwind } 398 399