1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes='simple-loop-unswitch<nontrivial>' -S < %s | FileCheck %s
4 ; If we try to replace uses of `true` outside of `@foo`, we'll see it here.
7 ; CHECK-NEXT: ret i1 true
12 ; We shouldn't unswitch this loop.
16 ; CHECK-NEXT: br label [[HEADER:%.*]]
18 ; CHECK-NEXT: [[VAL:%.*]] = select i1 true, i1 true, i1 false
19 ; CHECK-NEXT: br i1 [[VAL]], label [[EXIT:%.*]], label [[HEADER]]
21 ; CHECK-NEXT: ret void
27 %val = select i1 true, i1 true, i1 false
28 br i1 %val, label %exit, label %header
34 define void @unswitch_trivial_select(i1 %c.1, i1 %c.2, i8 %a) {
35 ; CHECK-LABEL: @unswitch_trivial_select(
37 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[PH_1:%.*]], label [[EXIT:%.*]]
39 ; CHECK-NEXT: br i1 [[C_2:%.*]], label [[PH_2:%.*]], label [[EXIT]]
41 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], 30
42 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i1 true, i1 false
43 ; CHECK-NEXT: [[CMP_FR:%.*]] = freeze i1 [[CMP]]
44 ; CHECK-NEXT: br i1 [[CMP_FR]], label [[PH_2_SPLIT_US:%.*]], label [[PH_2_SPLIT:%.*]]
45 ; CHECK: ph.2.split.us:
46 ; CHECK-NEXT: br label [[LOOP_US:%.*]]
48 ; CHECK-NEXT: call void @foo()
49 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT_SPLIT_US:%.*]]
50 ; CHECK: exit.loopexit.split.us:
51 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT:%.*]]
53 ; CHECK-NEXT: br label [[LOOP:%.*]]
55 ; CHECK-NEXT: call void @foo()
56 ; CHECK-NEXT: br label [[LOOP_LATCH:%.*]]
58 ; CHECK-NEXT: br label [[LOOP]]
59 ; CHECK: exit.loopexit:
60 ; CHECK-NEXT: br label [[EXIT]]
62 ; CHECK-NEXT: ret void
65 br i1 %c.1, label %ph.1, label %exit
68 br i1 %c.2, label %ph.2, label %exit
71 %cmp = icmp eq i8 %a, 30
72 %sel = select i1 %cmp, i1 true, i1 false
77 br i1 %sel, label %exit, label %loop.latch
86 ; Test case for PR55697.
87 define i32 @unswitch_trivial_select_cmp_outside(i32 %x) {
88 ; CHECK-LABEL: @unswitch_trivial_select_cmp_outside(
90 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X:%.*]], 100
91 ; CHECK-NEXT: br i1 [[C]], label [[ENTRY_SPLIT_US:%.*]], label [[ENTRY_SPLIT:%.*]]
92 ; CHECK: entry.split.us:
93 ; CHECK-NEXT: br label [[LOOP_US:%.*]]
95 ; CHECK-NEXT: [[P_US:%.*]] = phi i32 [ 0, [[ENTRY_SPLIT_US]] ], [ 35, [[LOOP_US]] ]
96 ; CHECK-NEXT: br label [[LOOP_US]]
98 ; CHECK-NEXT: br label [[LOOP:%.*]]
100 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[ENTRY_SPLIT]] ]
101 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 false, i1 true, i1 false
102 ; CHECK-NEXT: br label [[EXIT:%.*]]
104 ; CHECK-NEXT: [[LCSSA:%.*]] = phi i32 [ [[P]], [[LOOP]] ]
105 ; CHECK-NEXT: ret i32 [[LCSSA]]
108 %c = icmp ult i32 %x, 100
112 %p = phi i32 [ 0, %entry ], [ 35, %loop ]
113 %spec.select = select i1 %c, i1 true, i1 false
114 br i1 %spec.select, label %loop, label %exit
117 %lcssa = phi i32 [ %p, %loop ]