xref: /llvm-project/llvm/test/Transforms/PGOProfile/irreducible.ll (revision 9ff36df5a4a7d52c51e950522870bb64912688d2)
1cee313d2SEric Christopher; RUN: llvm-profdata merge %S/Inputs/irreducible.proftext -o %t.profdata
250da55a5SRong Xu; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
350da55a5SRong Xu; RUN: llvm-profdata merge %S/Inputs/irreducible_entry.proftext -o %t2.profdata
450da55a5SRong Xu; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE
5cee313d2SEric Christopher
6cee313d2SEric Christopher; GEN: $__llvm_profile_raw_version = comdat any
7cee313d2SEric Christopher
8cee313d2SEric Christopher; Function Attrs: noinline norecurse nounwind readnone uwtable
9cee313d2SEric Christopherdefine i32 @_Z11irreducibleii(i32 %iter_outer, i32 %iter_inner) local_unnamed_addr #0 {
10cee313d2SEric Christopherentry:
11cee313d2SEric Christopher  %cmp24 = icmp sgt i32 %iter_outer, 0
12cee313d2SEric Christopher  br i1 %cmp24, label %for.body, label %entry.for.cond.cleanup_crit_edge
13cee313d2SEric Christopher
14cee313d2SEric Christopherentry.for.cond.cleanup_crit_edge:                 ; preds = %entry
15cee313d2SEric Christopher  br label %for.cond.cleanup
16cee313d2SEric Christopher
17cee313d2SEric Christopherfor.cond.cleanup:                                 ; preds = %entry.for.cond.cleanup_crit_edge, %for.end
18cee313d2SEric Christopher  %sum.0.lcssa = phi i32 [ 0, %entry.for.cond.cleanup_crit_edge ], [ %sum.1, %for.end ]
19cee313d2SEric Christopher  ret i32 %sum.0.lcssa
20cee313d2SEric Christopher
21cee313d2SEric Christopherfor.body:                                         ; preds = %entry, %for.end
22cee313d2SEric Christopher  %k.026 = phi i32 [ %inc12, %for.end ], [ 0, %entry ]
23cee313d2SEric Christopher  %sum.025 = phi i32 [ %sum.1, %for.end ], [ 0, %entry ]
24cee313d2SEric Christopher  %rem23 = and i32 %k.026, 1
25cee313d2SEric Christopher  %cmp1 = icmp eq i32 %rem23, 0
26cee313d2SEric Christopher  br i1 %cmp1, label %entry8, label %for.cond2
27cee313d2SEric Christopher
28cee313d2SEric Christopherfor.cond2:                                        ; preds = %for.body, %if.end9
29cee313d2SEric Christopher  %sum.1 = phi i32 [ %add10, %if.end9 ], [ %sum.025, %for.body ]
30cee313d2SEric Christopher  %i.0 = phi i32 [ %inc, %if.end9 ], [ 0, %for.body ]
31cee313d2SEric Christopher  %cmp3 = icmp slt i32 %i.0, %iter_inner
32cee313d2SEric Christopher  br i1 %cmp3, label %for.body4, label %for.end
33cee313d2SEric Christopher; USE: br i1 %cmp3, label %for.body4, label %for.end, !prof !{{[0-9]+}},
34cee313d2SEric Christopher; USE-SAME: !irr_loop ![[FOR_COND2_IRR_LOOP:[0-9]+]]
35cee313d2SEric Christopher
36cee313d2SEric Christopherfor.body4:                                        ; preds = %for.cond2
37cee313d2SEric Christopher  %rem5 = srem i32 %k.026, 3
38cee313d2SEric Christopher  %cmp6 = icmp eq i32 %rem5, 0
39cee313d2SEric Christopher  br i1 %cmp6, label %entry8, label %if.end9
40cee313d2SEric Christopher
41cee313d2SEric Christopherentry8:                                           ; preds = %for.body4, %for.body
42cee313d2SEric Christopher  %sum.2 = phi i32 [ %sum.025, %for.body ], [ %sum.1, %for.body4 ]
43cee313d2SEric Christopher  %i.1 = phi i32 [ 0, %for.body ], [ %i.0, %for.body4 ]
44cee313d2SEric Christopher  %add = add nsw i32 %sum.2, 4
45cee313d2SEric Christopher  br label %if.end9
46cee313d2SEric Christopher; USE: br label %if.end9,
47cee313d2SEric Christopher; USE-SAME: !irr_loop ![[ENTRY8_IRR_LOOP:[0-9]+]]
48cee313d2SEric Christopher
49cee313d2SEric Christopherif.end9:                                          ; preds = %entry8, %for.body4
50cee313d2SEric Christopher  %sum.3 = phi i32 [ %add, %entry8 ], [ %sum.1, %for.body4 ]
51cee313d2SEric Christopher  %i.2 = phi i32 [ %i.1, %entry8 ], [ %i.0, %for.body4 ]
52cee313d2SEric Christopher  %add10 = add nsw i32 %sum.3, 1
53cee313d2SEric Christopher  %inc = add nsw i32 %i.2, 1
54cee313d2SEric Christopher  br label %for.cond2
55cee313d2SEric Christopher; USE: br label %for.cond2,
56cee313d2SEric Christopher; USE-SAME: !irr_loop ![[IF_END9_IRR_LOOP:[0-9]+]]
57cee313d2SEric Christopher
58cee313d2SEric Christopherfor.end:                                          ; preds = %for.cond2
59cee313d2SEric Christopher  %inc12 = add nuw nsw i32 %k.026, 1
60cee313d2SEric Christopher  %exitcond = icmp eq i32 %inc12, %iter_outer
61cee313d2SEric Christopher  br i1 %exitcond, label %for.cond.cleanup, label %for.body
62cee313d2SEric Christopher}
63cee313d2SEric Christopher
64cee313d2SEric Christopher
65cee313d2SEric Christopher
66*9ff36df5SFangrui Song@targets = local_unnamed_addr global [256 x ptr] zeroinitializer, align 16
67cee313d2SEric Christopher@tracing = local_unnamed_addr global i32 0, align 4
68cee313d2SEric Christopher
69cee313d2SEric Christopher; Function Attrs: noinline norecurse nounwind uwtable
70*9ff36df5SFangrui Songdefine i32 @_Z11irreduciblePh(ptr nocapture readonly %p) {
71cee313d2SEric Christopherentry:
72*9ff36df5SFangrui Song  %0 = load i32, ptr @tracing, align 4
73cee313d2SEric Christopher  %1 = trunc i32 %0 to i8
74cee313d2SEric Christopher  %tobool = icmp eq i32 %0, 0
75cee313d2SEric Christopher  br label %for.cond1
76cee313d2SEric Christopher
77cee313d2SEric Christopherfor.cond1:                                        ; preds = %sw.default, %entry
78cee313d2SEric Christopher  br label %dispatch_op
79cee313d2SEric Christopher
80cee313d2SEric Christopherdispatch_op:                                      ; preds = %sw.bb6, %for.cond1
81cee313d2SEric Christopher  switch i8 %1, label %sw.default [
82cee313d2SEric Christopher    i8 0, label %sw.bb
83cee313d2SEric Christopher    i8 1, label %dispatch_op.sw.bb6_crit_edge
84cee313d2SEric Christopher    i8 2, label %sw.bb15
85cee313d2SEric Christopher  ]
86cee313d2SEric Christopher
87cee313d2SEric Christopherdispatch_op.sw.bb6_crit_edge:                     ; preds = %dispatch_op
88cee313d2SEric Christopher  br label %sw.bb6
89cee313d2SEric Christopher
90cee313d2SEric Christophersw.bb:                                            ; preds = %indirectgoto, %dispatch_op
91cee313d2SEric Christopher  br label %exit
92cee313d2SEric Christopher
93cee313d2SEric ChristopherTARGET_1:                                         ; preds = %indirectgoto
94cee313d2SEric Christopher  br label %sw.bb6
95cee313d2SEric Christopher; USE: br label %sw.bb6, !irr_loop {{.*}}
96cee313d2SEric Christopher
97cee313d2SEric Christophersw.bb6:                                           ; preds = %TARGET_1, %dispatch_op.sw.bb6_crit_edge
98cee313d2SEric Christopher  br i1 %tobool, label %dispatch_op, label %if.then
99cee313d2SEric Christopher; USE: br i1 %tobool, label %dispatch_op, label %if.then, !prof !{{[0-9]+}},
100cee313d2SEric Christopher; USE-SAME: !irr_loop ![[SW_BB6_IRR_LOOP:[0-9]+]]
101cee313d2SEric Christopher
102cee313d2SEric Christopherif.then:                                          ; preds = %sw.bb6
103cee313d2SEric Christopher  br label %indirectgoto
104cee313d2SEric Christopher
105cee313d2SEric ChristopherTARGET_2:                                         ; preds = %indirectgoto
106cee313d2SEric Christopher  br label %sw.bb15
107cee313d2SEric Christopher; USE: br label %sw.bb15, !irr_loop {{.*}}
108cee313d2SEric Christopher
109cee313d2SEric Christophersw.bb15:                                          ; preds = %TARGET_2, %dispatch_op
110cee313d2SEric Christopher  br i1 %tobool, label %if.then18, label %exit
111cee313d2SEric Christopher; USE: br i1 %tobool, label %if.then18, label %exit, !prof !{{[0-9]+}},
112cee313d2SEric Christopher; USE-SAME: !irr_loop ![[SW_BB15_IRR_LOOP:[0-9]+]]
113cee313d2SEric Christopher
114cee313d2SEric Christopherif.then18:                                        ; preds = %sw.bb15
115cee313d2SEric Christopher  br label %indirectgoto
116cee313d2SEric Christopher
117cee313d2SEric Christopherunknown_op:                                       ; preds = %indirectgoto
118cee313d2SEric Christopher  br label %sw.default
119cee313d2SEric Christopher
120cee313d2SEric Christophersw.default:                                       ; preds = %unknown_op, %dispatch_op
121cee313d2SEric Christopher  br label %for.cond1
122cee313d2SEric Christopher
123cee313d2SEric Christopherexit:                                             ; preds = %sw.bb15, %sw.bb
124cee313d2SEric Christopher  ret i32 0
125cee313d2SEric Christopher
126cee313d2SEric Christopherindirectgoto:                                     ; preds = %if.then18, %if.then
127cee313d2SEric Christopher  %idxprom21 = zext i32 %0 to i64
128*9ff36df5SFangrui Song  %arrayidx22 = getelementptr inbounds [256 x ptr], ptr @targets, i64 0, i64 %idxprom21
129*9ff36df5SFangrui Song  %target = load ptr, ptr %arrayidx22, align 8
130*9ff36df5SFangrui Song  indirectbr ptr %target, [label %unknown_op, label %sw.bb, label %TARGET_1, label %TARGET_2]
131*9ff36df5SFangrui Song; USE: indirectbr ptr %target, [label %unknown_op, label %sw.bb, label %TARGET_1, label %TARGET_2], !prof !{{[0-9]+}},
132cee313d2SEric Christopher; USE-SAME: !irr_loop ![[INDIRECTGOTO_IRR_LOOP:[0-9]+]]
133cee313d2SEric Christopher}
134cee313d2SEric Christopher
135cee313d2SEric Christopher; USE: ![[FOR_COND2_IRR_LOOP]] = !{!"loop_header_weight", i64 1050}
136cee313d2SEric Christopher; USE: ![[ENTRY8_IRR_LOOP]] = !{!"loop_header_weight", i64 373}
137cee313d2SEric Christopher; USE: ![[IF_END9_IRR_LOOP]] = !{!"loop_header_weight", i64 1000}
138cee313d2SEric Christopher; USE: ![[SW_BB6_IRR_LOOP]] = !{!"loop_header_weight", i64 501}
139cee313d2SEric Christopher; USE: ![[SW_BB15_IRR_LOOP]] = !{!"loop_header_weight", i64 100}
1406a383369SMatthias Braun; USE: ![[INDIRECTGOTO_IRR_LOOP]] = !{!"loop_header_weight", i64 399}
141