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 ptr [ [[SCEVGEP:%.*]], [[LOOP]] ], [ null, [[ENTRY:%.*]] ]
20 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV]], i64 1
21 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[LOOPEXIT:%.*]]
23 ; CHECK-NEXT: [[SCEVGEP_LCSSA:%.*]] = phi ptr [ [[SCEVGEP]], [[LOOP]] ]
24 ; CHECK-NEXT: br i1 false, label [[BBA:%.*]], label [[BBB:%.*]]
26 ; CHECK-NEXT: switch i32 0, label [[BBA_BB89_CRIT_EDGE:%.*]] [
27 ; CHECK-NEXT: i32 47, label [[BBA_BB89_CRIT_EDGE]]
28 ; CHECK-NEXT: i32 58, label [[BBA_BB89_CRIT_EDGE]]
30 ; CHECK: bbA.bb89_crit_edge:
31 ; CHECK-NEXT: br label [[BB89:%.*]]
33 ; CHECK-NEXT: switch i8 0, label [[BBB_BB89_CRIT_EDGE:%.*]] [
34 ; CHECK-NEXT: i8 47, label [[BBB_BB89_CRIT_EDGE]]
35 ; CHECK-NEXT: i8 58, label [[BBB_BB89_CRIT_EDGE]]
37 ; CHECK: bbB.bb89_crit_edge:
38 ; CHECK-NEXT: br label [[BB89]]
40 ; CHECK-NEXT: [[TMP75PHI:%.*]] = phi ptr [ [[SCEVGEP_LCSSA]], [[BBA_BB89_CRIT_EDGE]] ], [ [[SCEVGEP_LCSSA]], [[BBB_BB89_CRIT_EDGE]] ]
41 ; CHECK-NEXT: br label [[EXIT:%.*]]
43 ; CHECK-NEXT: ret ptr [[TMP75PHI]]
49 %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
50 %next = add i32 %rec, 1
51 %tmp75 = getelementptr i8, ptr null, i32 %next
52 br i1 false, label %loop, label %loopexit
55 br i1 false, label %bbA, label %bbB
58 switch i32 0, label %bb89 [
64 switch i8 0, label %bb89 [
70 %tmp75phi = phi ptr [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]
77 ; Handle single-predecessor phis: PR13756
80 ; CHECK-LABEL: @test2(
82 ; CHECK-NEXT: br label [[LOOP:%.*]]
84 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[LOOP]] ], [ null, [[ENTRY:%.*]] ]
85 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV]], i64 1
86 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[LOOPEXIT:%.*]]
88 ; CHECK-NEXT: [[SCEVGEP_LCSSA:%.*]] = phi ptr [ [[SCEVGEP]], [[LOOP]] ]
89 ; CHECK-NEXT: br i1 false, label [[BBA:%.*]], label [[BBB:%.*]]
91 ; CHECK-NEXT: switch i32 0, label [[BB89:%.*]] [
92 ; CHECK-NEXT: i32 47, label [[BB89]]
93 ; CHECK-NEXT: i32 58, label [[BB89]]
96 ; CHECK-NEXT: switch i8 0, label [[BBB_EXIT_CRIT_EDGE:%.*]] [
97 ; CHECK-NEXT: i8 47, label [[BBB_EXIT_CRIT_EDGE]]
98 ; CHECK-NEXT: i8 58, label [[BBB_EXIT_CRIT_EDGE]]
100 ; CHECK: bbB.exit_crit_edge:
101 ; CHECK-NEXT: br label [[EXIT:%.*]]
103 ; CHECK-NEXT: [[TMP75PHI:%.*]] = phi ptr [ [[SCEVGEP_LCSSA]], [[BBA]] ], [ [[SCEVGEP_LCSSA]], [[BBA]] ], [ [[SCEVGEP_LCSSA]], [[BBA]] ]
104 ; CHECK-NEXT: br label [[EXIT]]
106 ; CHECK-NEXT: [[RESULT:%.*]] = phi ptr [ [[TMP75PHI]], [[BB89]] ], [ [[SCEVGEP_LCSSA]], [[BBB_EXIT_CRIT_EDGE]] ]
107 ; CHECK-NEXT: ret ptr [[RESULT]]
113 %rec = phi i32 [ %next, %loop ], [ 0, %entry ]
114 %next = add i32 %rec, 1
115 %tmp75 = getelementptr i8, ptr null, i32 %next
116 br i1 false, label %loop, label %loopexit
119 br i1 false, label %bbA, label %bbB
122 switch i32 0, label %bb89 [
128 switch i8 0, label %exit [
134 %tmp75phi = phi ptr [ %tmp75, %bbA ], [ %tmp75, %bbA ], [ %tmp75, %bbA ]
138 %result = phi ptr [ %tmp75phi, %bb89 ], [ %tmp75, %bbB ], [ %tmp75, %bbB ], [ %tmp75, %bbB ]