1 ; RUN: opt -S -jump-threading < %s | FileCheck %s
9 ; Jump threading of branch with select as condition.
10 ; Mostly theoretical since instruction combining simplifies all selects of
11 ; booleans where at least one operand is true/false/undef.
15 ; CHECK-NEXT: br i1 %cond, label %L1,
16 define void @test_br(i1 %cond, i1 %value) nounwind {
18 br i1 %cond, label %L0, label %L3
20 %expr = select i1 %cond, i1 true, i1 %value
21 br i1 %expr, label %L1, label %L2
35 ; Jump threading of switch with select as condition.
39 ; CHECK-NEXT: br i1 %cond, label %L1,
40 define void @test_switch(i1 %cond, i8 %value) nounwind {
42 br i1 %cond, label %L0, label %L4
44 %expr = select i1 %cond, i8 1, i8 %value
45 switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]
61 ; Make sure the blocks in the indirectbr test aren't trivially removable as
62 ; successors by taking their addresses.
63 @anchor = constant [3 x i8*] [
64 i8* blockaddress(@test_indirectbr, %L1),
65 i8* blockaddress(@test_indirectbr, %L2),
66 i8* blockaddress(@test_indirectbr, %L3)
70 ; Jump threading of indirectbr with select as address.
72 ; CHECK: @test_indirectbr
74 ; CHECK-NEXT: br i1 %cond, label %L1, label %L3
75 define void @test_indirectbr(i1 %cond, i8* %address) nounwind {
77 br i1 %cond, label %L0, label %L3
79 %indirect.goto.dest = select i1 %cond, i8* blockaddress(@test_indirectbr, %L1), i8* %address
80 indirectbr i8* %indirect.goto.dest, [label %L1, label %L2, label %L3]
94 ; A more complicated case: the condition is a select based on a comparison.
96 ; CHECK: @test_switch_cmp
98 ; CHECK-NEXT: br i1 %cond, label %L0, label %[[THREADED:[A-Za-z.0-9]+]]
99 ; CHECK: [[THREADED]]:
100 ; CHECK-NEXT: call void @quux
101 ; CHECK-NEXT: br label %L1
102 define void @test_switch_cmp(i1 %cond, i32 %val, i8 %value) nounwind {
104 br i1 %cond, label %L0, label %L4
106 %val.phi = phi i32 [%val, %entry], [-1, %L4]
107 %cmp = icmp slt i32 %val.phi, 0
108 %expr = select i1 %cmp, i8 1, i8 %value
109 switch i8 %expr, label %L3 [i8 1, label %L1 i8 2, label %L2]