1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
3 ; RUN: opt < %s -passes='require<profile-summary>,function(loop-mssa(simple-loop-unswitch<nontrivial>))' -S | FileCheck %s
5 ;; Check that non-trivial loop unswitching is applied to a cold loop in a
8 ;; IR was generated from the following loop nest, profiled when called
9 ;; with M=1000 and N=0.
10 ;; void hotFunction(bool cond, int M, int N, int * A, int *B, int *C) {
11 ;; for (unsigned j = 0; j < M; j++)
12 ;; for (unsigned i=0; i < N; i++) {
13 ;; A[i] = B[i] + C[i];
14 ;; if (cond) do_something();
18 define void @_Z11hotFunctionbiiPiS_S_(i1 %cond, i32 %M, i32 %N, ptr %A, ptr %B, ptr %C) !prof !36 {
19 ; CHECK-LABEL: define void @_Z11hotFunctionbiiPiS_S_
20 ; CHECK-SAME: (i1 [[COND:%.*]], i32 [[M:%.*]], i32 [[N:%.*]], ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) !prof [[PROF33:![0-9]+]] {
22 ; CHECK-NEXT: [[CMP19_NOT:%.*]] = icmp eq i32 [[M]], 0
23 ; CHECK-NEXT: br i1 [[CMP19_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]], !prof [[PROF34:![0-9]+]]
24 ; CHECK: for.cond1.preheader.lr.ph:
25 ; CHECK-NEXT: [[CMP217_NOT:%.*]] = icmp eq i32 [[N]], 0
26 ; CHECK-NEXT: br i1 [[CMP217_NOT]], label [[FOR_COND1_PREHEADER_LR_PH_SPLIT_US:%.*]], label [[FOR_COND1_PREHEADER_LR_PH_SPLIT:%.*]], !prof [[PROF35:![0-9]+]]
27 ; CHECK: for.cond1.preheader.lr.ph.split.us:
28 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
29 ; CHECK: for.cond1.preheader.us:
30 ; CHECK-NEXT: [[J_020_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_LR_PH_SPLIT_US]] ], [ [[INC10_US:%.*]], [[FOR_COND_CLEANUP3_US:%.*]] ]
31 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP3_US]]
32 ; CHECK: for.cond.cleanup3.us:
33 ; CHECK-NEXT: [[INC10_US]] = add nuw i32 [[J_020_US]], 1
34 ; CHECK-NEXT: [[EXITCOND22_NOT_US:%.*]] = icmp eq i32 [[INC10_US]], [[M]]
35 ; CHECK-NEXT: br i1 [[EXITCOND22_NOT_US]], label [[FOR_COND_CLEANUP_LOOPEXIT_SPLIT_US:%.*]], label [[FOR_COND1_PREHEADER_US]], !prof [[PROF34]]
36 ; CHECK: for.cond.cleanup.loopexit.split.us:
37 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]]
38 ; CHECK: for.cond1.preheader.lr.ph.split:
39 ; CHECK-NEXT: br i1 [[COND]], label [[FOR_COND1_PREHEADER_LR_PH_SPLIT_SPLIT_US:%.*]], label [[FOR_COND1_PREHEADER_LR_PH_SPLIT_SPLIT:%.*]]
40 ; CHECK: for.cond1.preheader.lr.ph.split.split.us:
41 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US1:%.*]]
42 ; CHECK: for.cond1.preheader.us1:
43 ; CHECK-NEXT: [[J_020_US2:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_LR_PH_SPLIT_SPLIT_US]] ], [ [[INC10_US4:%.*]], [[FOR_COND_CLEANUP3_US3:%.*]] ]
44 ; CHECK-NEXT: br label [[FOR_BODY4_PREHEADER_US:%.*]]
45 ; CHECK: for.cond.cleanup3.us3:
46 ; CHECK-NEXT: [[INC10_US4]] = add nuw i32 [[J_020_US2]], 1
47 ; CHECK-NEXT: [[EXITCOND22_NOT_US5:%.*]] = icmp eq i32 [[INC10_US4]], [[M]]
48 ; CHECK-NEXT: br i1 [[EXITCOND22_NOT_US5]], label [[FOR_COND_CLEANUP_LOOPEXIT_SPLIT_SPLIT_US:%.*]], label [[FOR_COND1_PREHEADER_US1]], !prof [[PROF34]]
49 ; CHECK: for.body4.preheader.us:
50 ; CHECK-NEXT: br label [[FOR_BODY4_PREHEADER_SPLIT_US_US:%.*]]
51 ; CHECK: for.cond.cleanup3.loopexit.us:
52 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP3_US3]]
53 ; CHECK: for.body4.preheader.split.us.us:
54 ; CHECK-NEXT: br label [[FOR_BODY4_US_US:%.*]]
55 ; CHECK: for.body4.us.us:
56 ; CHECK-NEXT: [[INDVARS_IV_US_US:%.*]] = phi i64 [ [[INDVARS_IV_NEXT_US_US:%.*]], [[FOR_INC_US_US:%.*]] ], [ 0, [[FOR_BODY4_PREHEADER_SPLIT_US_US]] ]
57 ; CHECK-NEXT: [[ARRAYIDX_US_US:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[INDVARS_IV_US_US]]
58 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX_US_US]], align 4
59 ; CHECK-NEXT: [[ARRAYIDX6_US_US:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[INDVARS_IV_US_US]]
60 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX6_US_US]], align 4
61 ; CHECK-NEXT: [[ADD_US_US:%.*]] = add nsw i32 [[TMP1]], [[TMP0]]
62 ; CHECK-NEXT: [[ARRAYIDX8_US_US:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV_US_US]]
63 ; CHECK-NEXT: store i32 [[ADD_US_US]], ptr [[ARRAYIDX8_US_US]], align 4
64 ; CHECK-NEXT: br label [[IF_THEN_US_US:%.*]]
65 ; CHECK: if.then.us.us:
66 ; CHECK-NEXT: tail call void @_Z12do_somethingv()
67 ; CHECK-NEXT: br label [[FOR_INC_US_US]]
68 ; CHECK: for.inc.us.us:
69 ; CHECK-NEXT: [[WIDE_TRIP_COUNT_US_US:%.*]] = zext i32 [[N]] to i64
70 ; CHECK-NEXT: [[INDVARS_IV_NEXT_US_US]] = add nuw nsw i64 [[INDVARS_IV_US_US]], 1
71 ; CHECK-NEXT: [[EXITCOND_NOT_US_US:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT_US_US]], [[WIDE_TRIP_COUNT_US_US]]
72 ; CHECK-NEXT: br i1 [[EXITCOND_NOT_US_US]], label [[FOR_COND_CLEANUP3_LOOPEXIT_SPLIT_US_US:%.*]], label [[FOR_BODY4_US_US]], !prof [[PROF35]]
73 ; CHECK: for.cond.cleanup3.loopexit.split.us.us:
74 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP3_LOOPEXIT_US:%.*]]
75 ; CHECK: for.cond.cleanup.loopexit.split.split.us:
76 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT_SPLIT:%.*]]
77 ; CHECK: for.cond1.preheader.lr.ph.split.split:
78 ; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
79 ; CHECK: for.cond1.preheader:
80 ; CHECK-NEXT: [[J_020:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_LR_PH_SPLIT_SPLIT]] ], [ [[INC10:%.*]], [[FOR_COND_CLEANUP3:%.*]] ]
81 ; CHECK-NEXT: br label [[FOR_BODY4_PREHEADER:%.*]]
82 ; CHECK: for.body4.preheader:
83 ; CHECK-NEXT: br label [[FOR_BODY4_PREHEADER_SPLIT:%.*]]
84 ; CHECK: for.body4.preheader.split:
85 ; CHECK-NEXT: br label [[FOR_BODY4:%.*]]
86 ; CHECK: for.cond.cleanup.loopexit.split.split:
87 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT_SPLIT]]
88 ; CHECK: for.cond.cleanup.loopexit.split:
89 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP_LOOPEXIT]]
90 ; CHECK: for.cond.cleanup.loopexit:
91 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
92 ; CHECK: for.cond.cleanup:
93 ; CHECK-NEXT: ret void
94 ; CHECK: for.cond.cleanup3.loopexit.split:
95 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP3_LOOPEXIT:%.*]]
96 ; CHECK: for.cond.cleanup3.loopexit:
97 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP3]]
98 ; CHECK: for.cond.cleanup3:
99 ; CHECK-NEXT: [[INC10]] = add nuw i32 [[J_020]], 1
100 ; CHECK-NEXT: [[EXITCOND22_NOT:%.*]] = icmp eq i32 [[INC10]], [[M]]
101 ; CHECK-NEXT: br i1 [[EXITCOND22_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT_SPLIT_SPLIT:%.*]], label [[FOR_COND1_PREHEADER]], !prof [[PROF34]]
103 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC:%.*]] ], [ 0, [[FOR_BODY4_PREHEADER_SPLIT]] ]
104 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[INDVARS_IV]]
105 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
106 ; CHECK-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[INDVARS_IV]]
107 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX6]], align 4
108 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP3]], [[TMP2]]
109 ; CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
110 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX8]], align 4
111 ; CHECK-NEXT: br label [[FOR_INC]]
113 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
114 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
115 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
116 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP3_LOOPEXIT_SPLIT:%.*]], label [[FOR_BODY4]], !prof [[PROF35]]
119 %cmp19.not = icmp eq i32 %M, 0
120 br i1 %cmp19.not, label %for.cond.cleanup, label %for.cond1.preheader.lr.ph, !prof !37
122 for.cond1.preheader.lr.ph:
123 %cmp217.not = icmp eq i32 %N, 0
124 br label %for.cond1.preheader
127 %j.020 = phi i32 [ 0, %for.cond1.preheader.lr.ph ], [ %inc10, %for.cond.cleanup3 ]
128 br i1 %cmp217.not, label %for.cond.cleanup3, label %for.body4, !prof !38
134 %inc10 = add nuw i32 %j.020, 1
135 %exitcond22.not = icmp eq i32 %inc10, %M
136 br i1 %exitcond22.not, label %for.cond.cleanup, label %for.cond1.preheader, !prof !37
139 %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %for.cond1.preheader ]
140 %arrayidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv
141 %0 = load i32, ptr %arrayidx, align 4
142 %arrayidx6 = getelementptr inbounds i32, ptr %C, i64 %indvars.iv
143 %1 = load i32, ptr %arrayidx6, align 4
144 %add = add nsw i32 %1, %0
145 %arrayidx8 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
146 store i32 %add, ptr %arrayidx8, align 4
147 br i1 %cond, label %if.then, label %for.inc
150 tail call void @_Z12do_somethingv()
154 %wide.trip.count = zext i32 %N to i64
155 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
156 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
157 br i1 %exitcond.not, label %for.cond.cleanup3, label %for.body4, !prof !38
160 declare void @_Z12do_somethingv()
162 !llvm.module.flags = !{!6}
164 !6 = !{i32 1, !"ProfileSummary", !7}
165 !7 = !{!8, !9, !10, !11, !12, !13, !14, !15, !16, !17}
166 !8 = !{!"ProfileFormat", !"InstrProf"}
167 !9 = !{!"TotalCount", i64 1002}
168 !10 = !{!"MaxCount", i64 1000}
169 !11 = !{!"MaxInternalCount", i64 1000}
170 !12 = !{!"MaxFunctionCount", i64 1}
171 !13 = !{!"NumCounts", i64 6}
172 !14 = !{!"NumFunctions", i64 3}
173 !15 = !{!"IsPartialProfile", i64 0}
174 !16 = !{!"PartialProfileRatio", double 0.000000e+00}
175 !17 = !{!"DetailedSummary", !18}
176 !18 = !{!19, !31, !34}
177 !19 = !{i32 10000, i64 1000, i32 1}
178 !31 = !{i32 999000, i64 1000, i32 1}
179 !34 = !{i32 999999, i64 1, i32 3}
180 !36 = !{!"function_entry_count", i64 1}
181 !37 = !{!"branch_weights", i32 1, i32 1000}
182 !38 = !{!"branch_weights", i32 1000, i32 0}