398 lines · plain
1; RUN: opt -S -passes='bdce,instsimplify' < %s | FileCheck %s2; RUN: opt -S -passes=instsimplify < %s | FileCheck %s -check-prefix=CHECK-IO3; RUN: opt -S -passes='debugify,bdce' < %s | FileCheck %s -check-prefix=DEBUGIFY4target datalayout = "E-m:e-i64:64-n32:64"5target triple = "powerpc64-unknown-linux-gnu"6 7; Function Attrs: nounwind readnone8define signext i32 @bar(i32 signext %x) #0 {9entry:10 %call = tail call signext i32 @foo(i32 signext 5) #011 %and = and i32 %call, 412 %or = or i32 %and, %x13 %call1 = tail call signext i32 @foo(i32 signext 3) #014 %and2 = and i32 %call1, 815 %or3 = or i32 %or, %and216 %call4 = tail call signext i32 @foo(i32 signext 2) #017 %and5 = and i32 %call4, 1618 %or6 = or i32 %or3, %and519 %call7 = tail call signext i32 @foo(i32 signext 1) #020 %and8 = and i32 %call7, 3221 %or9 = or i32 %or6, %and822 %call10 = tail call signext i32 @foo(i32 signext 0) #023 %and11 = and i32 %call10, 6424 %or12 = or i32 %or9, %and1125 %call13 = tail call signext i32 @foo(i32 signext 4) #026 %and14 = and i32 %call13, 12827 %or15 = or i32 %or12, %and1428 %shr = ashr i32 %or15, 429 ret i32 %shr30 31; CHECK-LABEL: @bar32; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)33; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)34; CHECK: tail call signext i32 @foo(i32 signext 2)35; CHECK: tail call signext i32 @foo(i32 signext 1)36; CHECK: tail call signext i32 @foo(i32 signext 0)37; CHECK: tail call signext i32 @foo(i32 signext 4)38; CHECK: ret i3239 40; Check that instsimplify is not doing this all on its own.41; CHECK-IO-LABEL: @bar42; CHECK-IO: tail call signext i32 @foo(i32 signext 5)43; CHECK-IO: tail call signext i32 @foo(i32 signext 3)44; CHECK-IO: tail call signext i32 @foo(i32 signext 2)45; CHECK-IO: tail call signext i32 @foo(i32 signext 1)46; CHECK-IO: tail call signext i32 @foo(i32 signext 0)47; CHECK-IO: tail call signext i32 @foo(i32 signext 4)48; CHECK-IO: ret i3249}50 51; Function Attrs: nounwind readnone52declare signext i32 @foo(i32 signext) #053 54; Function Attrs: nounwind readnone55define signext i32 @far(i32 signext %x) #1 {56entry:57 %call = tail call signext i32 @goo(i32 signext 5) #158 %and = and i32 %call, 459 %or = or i32 %and, %x60 %call1 = tail call signext i32 @goo(i32 signext 3) #161 %and2 = and i32 %call1, 862 %or3 = or i32 %or, %and263 %call4 = tail call signext i32 @goo(i32 signext 2) #164 %and5 = and i32 %call4, 1665 %or6 = or i32 %or3, %and566 %call7 = tail call signext i32 @goo(i32 signext 1) #167 %and8 = and i32 %call7, 3268 %or9 = or i32 %or6, %and869 %call10 = tail call signext i32 @goo(i32 signext 0) #170 %and11 = and i32 %call10, 6471 %or12 = or i32 %or9, %and1172 %call13 = tail call signext i32 @goo(i32 signext 4) #173 %and14 = and i32 %call13, 12874 %or15 = or i32 %or12, %and1475 %shr = ashr i32 %or15, 476 ret i32 %shr77 78; CHECK-LABEL: @far79; Calls to foo(5) and foo(3) are still there, but their results are not used.80; CHECK: tail call signext i32 @goo(i32 signext 5)81; CHECK-NEXT: tail call signext i32 @goo(i32 signext 3)82; CHECK-NEXT: tail call signext i32 @goo(i32 signext 2)83; CHECK: tail call signext i32 @goo(i32 signext 1)84; CHECK: tail call signext i32 @goo(i32 signext 0)85; CHECK: tail call signext i32 @goo(i32 signext 4)86; CHECK: ret i3287 88; Check that instsimplify is not doing this all on its own.89; CHECK-IO-LABEL: @far90; CHECK-IO: tail call signext i32 @goo(i32 signext 5)91; CHECK-IO: tail call signext i32 @goo(i32 signext 3)92; CHECK-IO: tail call signext i32 @goo(i32 signext 2)93; CHECK-IO: tail call signext i32 @goo(i32 signext 1)94; CHECK-IO: tail call signext i32 @goo(i32 signext 0)95; CHECK-IO: tail call signext i32 @goo(i32 signext 4)96; CHECK-IO: ret i3297}98 99declare signext i32 @goo(i32 signext) #1100 101; Function Attrs: nounwind readnone102define signext i32 @tar1(i32 signext %x) #0 {103entry:104 %call = tail call signext i32 @foo(i32 signext 5) #0105 %and = and i32 %call, 33554432106 %or = or i32 %and, %x107 %call1 = tail call signext i32 @foo(i32 signext 3) #0108 %and2 = and i32 %call1, 67108864109 %or3 = or i32 %or, %and2110 %call4 = tail call signext i32 @foo(i32 signext 2) #0111 %and5 = and i32 %call4, 16112 %or6 = or i32 %or3, %and5113 %call7 = tail call signext i32 @foo(i32 signext 1) #0114 %and8 = and i32 %call7, 32115 %or9 = or i32 %or6, %and8116 %call10 = tail call signext i32 @foo(i32 signext 0) #0117 %and11 = and i32 %call10, 64118 %or12 = or i32 %or9, %and11119 %call13 = tail call signext i32 @foo(i32 signext 4) #0120 %and14 = and i32 %call13, 128121 %or15 = or i32 %or12, %and14122 %bs = tail call i32 @llvm.bswap.i32(i32 %or15) #0123 %shr = ashr i32 %bs, 4124 ret i32 %shr125 126; CHECK-LABEL: @tar1127; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)128; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)129; CHECK: tail call signext i32 @foo(i32 signext 2)130; CHECK: tail call signext i32 @foo(i32 signext 1)131; CHECK: tail call signext i32 @foo(i32 signext 0)132; CHECK: tail call signext i32 @foo(i32 signext 4)133; CHECK: ret i32134}135 136; Function Attrs: nounwind readnone137declare i32 @llvm.bswap.i32(i32) #0138 139; Function Attrs: nounwind readnone140define signext i32 @tim(i32 signext %x) #0 {141entry:142 %call = tail call signext i32 @foo(i32 signext 5) #0143 %and = and i32 %call, 536870912144 %or = or i32 %and, %x145 %call1 = tail call signext i32 @foo(i32 signext 3) #0146 %and2 = and i32 %call1, 1073741824147 %or3 = or i32 %or, %and2148 %call4 = tail call signext i32 @foo(i32 signext 2) #0149 %and5 = and i32 %call4, 16150 %or6 = or i32 %or3, %and5151 %call7 = tail call signext i32 @foo(i32 signext 1) #0152 %and8 = and i32 %call7, 32153 %or9 = or i32 %or6, %and8154 %call10 = tail call signext i32 @foo(i32 signext 0) #0155 %and11 = and i32 %call10, 64156 %or12 = or i32 %or9, %and11157 %call13 = tail call signext i32 @foo(i32 signext 4) #0158 %and14 = and i32 %call13, 128159 %or15 = or i32 %or12, %and14160 %bs = tail call i32 @llvm.bitreverse.i32(i32 %or15) #0161 %shr = ashr i32 %bs, 4162 ret i32 %shr163 164; CHECK-LABEL: @tim165; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)166; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)167; CHECK: tail call signext i32 @foo(i32 signext 2)168; CHECK: tail call signext i32 @foo(i32 signext 1)169; CHECK: tail call signext i32 @foo(i32 signext 0)170; CHECK: tail call signext i32 @foo(i32 signext 4)171; CHECK: ret i32172}173 174; Function Attrs: nounwind readnone175declare i32 @llvm.bitreverse.i32(i32) #0176 177; Function Attrs: nounwind readnone178define signext i32 @tar2(i32 signext %x) #0 {179entry:180 %call = tail call signext i32 @foo(i32 signext 5) #0181 %and = and i32 %call, 33554432182 %or = or i32 %and, %x183 %call1 = tail call signext i32 @foo(i32 signext 3) #0184 %and2 = and i32 %call1, 67108864185 %or3 = or i32 %or, %and2186 %call4 = tail call signext i32 @foo(i32 signext 2) #0187 %and5 = and i32 %call4, 16188 %or6 = or i32 %or3, %and5189 %call7 = tail call signext i32 @foo(i32 signext 1) #0190 %and8 = and i32 %call7, 32191 %or9 = or i32 %or6, %and8192 %call10 = tail call signext i32 @foo(i32 signext 0) #0193 %and11 = and i32 %call10, 64194 %or12 = or i32 %or9, %and11195 %call13 = tail call signext i32 @foo(i32 signext 4) #0196 %and14 = and i32 %call13, 128197 %or15 = or i32 %or12, %and14198 %shl = shl i32 %or15, 10199 ret i32 %shl200 201; CHECK-LABEL: @tar2202; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)203; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)204; CHECK: tail call signext i32 @foo(i32 signext 2)205; CHECK: tail call signext i32 @foo(i32 signext 1)206; CHECK: tail call signext i32 @foo(i32 signext 0)207; CHECK: tail call signext i32 @foo(i32 signext 4)208; CHECK: ret i32209}210 211; Function Attrs: nounwind readnone212define signext i32 @tar3(i32 signext %x) #0 {213entry:214 %call = tail call signext i32 @foo(i32 signext 5) #0215 %and = and i32 %call, 33554432216 %or = or i32 %and, %x217 %call1 = tail call signext i32 @foo(i32 signext 3) #0218 %and2 = and i32 %call1, 67108864219 %or3 = or i32 %or, %and2220 %call4 = tail call signext i32 @foo(i32 signext 2) #0221 %and5 = and i32 %call4, 16222 %or6 = or i32 %or3, %and5223 %call7 = tail call signext i32 @foo(i32 signext 1) #0224 %and8 = and i32 %call7, 32225 %or9 = or i32 %or6, %and8226 %call10 = tail call signext i32 @foo(i32 signext 0) #0227 %and11 = and i32 %call10, 64228 %or12 = or i32 %or9, %and11229 %call13 = tail call signext i32 @foo(i32 signext 4) #0230 %and14 = and i32 %call13, 128231 %or15 = or i32 %or12, %and14232 %add = add i32 %or15, 5233 %shl = shl i32 %add, 10234 ret i32 %shl235 236; CHECK-LABEL: @tar3237; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)238; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)239; CHECK: tail call signext i32 @foo(i32 signext 2)240; CHECK: tail call signext i32 @foo(i32 signext 1)241; CHECK: tail call signext i32 @foo(i32 signext 0)242; CHECK: tail call signext i32 @foo(i32 signext 4)243; CHECK: ret i32244}245 246; Function Attrs: nounwind readnone247define signext i32 @tar4(i32 signext %x) #0 {248entry:249 %call = tail call signext i32 @foo(i32 signext 5) #0250 %and = and i32 %call, 33554432251 %or = or i32 %and, %x252 %call1 = tail call signext i32 @foo(i32 signext 3) #0253 %and2 = and i32 %call1, 67108864254 %or3 = or i32 %or, %and2255 %call4 = tail call signext i32 @foo(i32 signext 2) #0256 %and5 = and i32 %call4, 16257 %or6 = or i32 %or3, %and5258 %call7 = tail call signext i32 @foo(i32 signext 1) #0259 %and8 = and i32 %call7, 32260 %or9 = or i32 %or6, %and8261 %call10 = tail call signext i32 @foo(i32 signext 0) #0262 %and11 = and i32 %call10, 64263 %or12 = or i32 %or9, %and11264 %call13 = tail call signext i32 @foo(i32 signext 4) #0265 %and14 = and i32 %call13, 128266 %or15 = or i32 %or12, %and14267 %sub = sub i32 %or15, 5268 %shl = shl i32 %sub, 10269 ret i32 %shl270 271; CHECK-LABEL: @tar4272; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)273; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)274; CHECK: tail call signext i32 @foo(i32 signext 2)275; CHECK: tail call signext i32 @foo(i32 signext 1)276; CHECK: tail call signext i32 @foo(i32 signext 0)277; CHECK: tail call signext i32 @foo(i32 signext 4)278; CHECK: ret i32279}280 281; Function Attrs: nounwind readnone282define signext i32 @tar5(i32 signext %x) #0 {283entry:284 %call = tail call signext i32 @foo(i32 signext 5) #0285 %and = and i32 %call, 33554432286 %or = or i32 %and, %x287 %call1 = tail call signext i32 @foo(i32 signext 3) #0288 %and2 = and i32 %call1, 67108864289 %or3 = or i32 %or, %and2290 %call4 = tail call signext i32 @foo(i32 signext 2) #0291 %and5 = and i32 %call4, 16292 %or6 = or i32 %or3, %and5293 %call7 = tail call signext i32 @foo(i32 signext 1) #0294 %and8 = and i32 %call7, 32295 %or9 = or i32 %or6, %and8296 %call10 = tail call signext i32 @foo(i32 signext 0) #0297 %and11 = and i32 %call10, 64298 %or12 = or i32 %or9, %and11299 %call13 = tail call signext i32 @foo(i32 signext 4) #0300 %and14 = and i32 %call13, 128301 %or15 = or i32 %or12, %and14302 %xor = xor i32 %or15, 5303 %shl = shl i32 %xor, 10304 ret i32 %shl305 306; CHECK-LABEL: @tar5307; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)308; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)309; CHECK: tail call signext i32 @foo(i32 signext 2)310; CHECK: tail call signext i32 @foo(i32 signext 1)311; CHECK: tail call signext i32 @foo(i32 signext 0)312; CHECK: tail call signext i32 @foo(i32 signext 4)313; CHECK: ret i32314}315 316; Function Attrs: nounwind readnone317define signext i32 @tar7(i32 signext %x, i1 %b) #0 {318entry:319 %call = tail call signext i32 @foo(i32 signext 5) #0320 %and = and i32 %call, 33554432321 %or = or i32 %and, %x322 %call1 = tail call signext i32 @foo(i32 signext 3) #0323 %and2 = and i32 %call1, 67108864324 %or3 = or i32 %or, %and2325 %call4 = tail call signext i32 @foo(i32 signext 2) #0326 %and5 = and i32 %call4, 16327 %or6 = or i32 %or3, %and5328 %call7 = tail call signext i32 @foo(i32 signext 1) #0329 %and8 = and i32 %call7, 32330 %or9 = or i32 %or6, %and8331 %call10 = tail call signext i32 @foo(i32 signext 0) #0332 %and11 = and i32 %call10, 64333 %or12 = or i32 %or9, %and11334 %call13 = tail call signext i32 @foo(i32 signext 4) #0335 %and14 = and i32 %call13, 128336 %or15 = or i32 %or12, %and14337 %v = select i1 %b, i32 %or15, i32 5338 %shl = shl i32 %v, 10339 ret i32 %shl340 341; CHECK-LABEL: @tar7342; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)343; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)344; CHECK: tail call signext i32 @foo(i32 signext 2)345; CHECK: tail call signext i32 @foo(i32 signext 1)346; CHECK: tail call signext i32 @foo(i32 signext 0)347; CHECK: tail call signext i32 @foo(i32 signext 4)348; CHECK: ret i32349}350 351; Function Attrs: nounwind readnone352define signext i16 @tar8(i32 signext %x) #0 {353entry:354 %call = tail call signext i32 @foo(i32 signext 5) #0355 %and = and i32 %call, 33554432356 %or = or i32 %and, %x357 %call1 = tail call signext i32 @foo(i32 signext 3) #0358 %and2 = and i32 %call1, 67108864359 %or3 = or i32 %or, %and2360 %call4 = tail call signext i32 @foo(i32 signext 2) #0361 %and5 = and i32 %call4, 16362 %or6 = or i32 %or3, %and5363 %call7 = tail call signext i32 @foo(i32 signext 1) #0364 %and8 = and i32 %call7, 32365 %or9 = or i32 %or6, %and8366 %call10 = tail call signext i32 @foo(i32 signext 0) #0367 %and11 = and i32 %call10, 64368 %or12 = or i32 %or9, %and11369 %call13 = tail call signext i32 @foo(i32 signext 4) #0370 %and14 = and i32 %call13, 128371 %or15 = or i32 %or12, %and14372 %tr = trunc i32 %or15 to i16373 ret i16 %tr374 375; CHECK-LABEL: @tar8376; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)377; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)378; CHECK: tail call signext i32 @foo(i32 signext 2)379; CHECK: tail call signext i32 @foo(i32 signext 1)380; CHECK: tail call signext i32 @foo(i32 signext 0)381; CHECK: tail call signext i32 @foo(i32 signext 4)382; CHECK: ret i16383}384 385; DEBUGIFY-LABEL: @tar9386define signext i16 @tar9(i32 signext %x) #0 {387entry:388 %call = tail call signext i32 @foo(i32 signext 5) #0389 %and = and i32 %call, 33554432390; DEBUGIFY: #dbg_value(i32 %call, {{.*}}, !DIExpression(DW_OP_constu, 33554432, DW_OP_and, DW_OP_stack_value),391 %cast = trunc i32 %call to i16392 ret i16 %cast393}394 395attributes #0 = { nounwind readnone willreturn }396attributes #1 = { nounwind }397 398