1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
4 ; Test LSR's use of SplitCriticalEdge during phi rewriting.
6 target triple = "x86_64-apple-darwin"
8 ; Provide legal integer types.
9 target datalayout = "n8:16:32:64"
11 ; Verify that identical edges are merged. rdar://problem/6453893
15 ; CHECK-LABEL: @test1(
17 ; CHECK-NEXT: br label [[LOOP:%.*]]
19 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP:%.*]], [[LOOP]] ], [ null, [[ENTRY:%.*]] ]
20 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, i8* [[LSR_IV]], i64 1
21 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[LOOPEXIT:%.*]]
23 ; CHECK-NEXT: br i1 false, label [[BBA:%.*]], label [[BBB:%.*]]
25 ; CHECK-NEXT: switch i32 0, label [[BBA_BB89_CRIT_EDGE:%.*]] [
26 ; CHECK-NEXT: i32 47, label [[BBA_BB89_CRIT_EDGE]]
27 ; CHECK-NEXT: i32 58, label [[BBA_BB89_CRIT_EDGE]]
29 ; CHECK: bbA.bb89_crit_edge:
30 ; CHECK-NEXT: br label [[BB89:%.*]]
32 ; CHECK-NEXT: switch i8 0, label [[BBB_BB89_CRIT_EDGE:%.*]] [
33 ; CHECK-NEXT: i8 47, label [[BBB_BB89_CRIT_EDGE]]
34 ; CHECK-NEXT: i8 58, label [[BBB_BB89_CRIT_EDGE]]
36 ; CHECK: bbB.bb89_crit_edge:
37 ; CHECK-NEXT: br label [[BB89]]
39 ; CHECK-NEXT: [[TMP75PHI:%.*]] = phi i8* [ [[SCEVGEP]], [[BBA_BB89_CRIT_EDGE]] ], [ [[SCEVGEP]], [[BBB_BB89_CRIT_EDGE]] ]
40 ; CHECK-NEXT: br label [[EXIT:%.*]]
42 ; CHECK-NEXT: ret i8* [[TMP75PHI]]
48 %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
49 %next = add i32 %rec, 1
50 %tmp75 = getelementptr i8, i8* null, i32 %next
51 br i1 false, label %loop, label %loopexit
54 br i1 false, label %bbA, label %bbB
57 switch i32 0, label %bb89 [
63 switch i8 0, label %bb89 [
69 %tmp75phi = phi i8* [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]
76 ; Handle single-predecessor phis: PR13756
79 ; CHECK-LABEL: @test2(
81 ; CHECK-NEXT: br label [[LOOP:%.*]]
83 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i8* [ [[SCEVGEP:%.*]], [[LOOP]] ], [ null, [[ENTRY:%.*]] ]
84 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, i8* [[LSR_IV]], i64 1
85 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[LOOPEXIT:%.*]]
87 ; CHECK-NEXT: br i1 false, label [[BBA:%.*]], label [[BBB:%.*]]
89 ; CHECK-NEXT: switch i32 0, label [[BB89:%.*]] [
90 ; CHECK-NEXT: i32 47, label [[BB89]]
91 ; CHECK-NEXT: i32 58, label [[BB89]]
94 ; CHECK-NEXT: switch i8 0, label [[BBB_EXIT_CRIT_EDGE:%.*]] [
95 ; CHECK-NEXT: i8 47, label [[BBB_EXIT_CRIT_EDGE]]
96 ; CHECK-NEXT: i8 58, label [[BBB_EXIT_CRIT_EDGE]]
98 ; CHECK: bbB.exit_crit_edge:
99 ; CHECK-NEXT: br label [[EXIT:%.*]]
101 ; CHECK-NEXT: [[TMP75PHI:%.*]] = phi i8* [ [[SCEVGEP]], [[BBA]] ], [ [[SCEVGEP]], [[BBA]] ], [ [[SCEVGEP]], [[BBA]] ]
102 ; CHECK-NEXT: br label [[EXIT]]
104 ; CHECK-NEXT: [[RESULT:%.*]] = phi i8* [ [[TMP75PHI]], [[BB89]] ], [ [[SCEVGEP]], [[BBB_EXIT_CRIT_EDGE]] ]
105 ; CHECK-NEXT: ret i8* [[RESULT]]
111 %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
112 %next = add i32 %rec, 1
113 %tmp75 = getelementptr i8, i8* null, i32 %next
114 br i1 false, label %loop, label %loopexit
117 br i1 false, label %bbA, label %bbB
120 switch i32 0, label %bb89 [
126 switch i8 0, label %exit [
132 %tmp75phi = phi i8* [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ]
136 %result = phi i8* [ %tmp75phi, %bb89 ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]