xref: /llvm-project/llvm/test/Transforms/PGOProfile/counter_promo.ll (revision 41d5033eb162cb92b684855166cabfa3983b74c6)
131bd15c5SRong Xu; RUN: opt < %s --passes=pgo-instr-gen,instrprof -do-counter-promotion=true -skip-ret-exit-block=0 -S | FileCheck --check-prefix=PROMO --check-prefix=NONATOMIC_PROMO %s
231bd15c5SRong Xu; RUN: opt < %s --passes=pgo-instr-gen,instrprof -do-counter-promotion=true -atomic-counter-update-promoted -skip-ret-exit-block=0 -S | FileCheck --check-prefix=PROMO --check-prefix=ATOMIC_PROMO %s
3cee313d2SEric Christopher
4cee313d2SEric Christopherdefine void @foo(i32 %n, i32 %N) {
5cee313d2SEric Christopher; PROMO-LABEL: @foo
6cee313d2SEric Christopher; PROMO: {{.*}} = load {{.*}} @__profc_foo{{.*}} 3)
7cee313d2SEric Christopher; PROMO-NEXT: add
8cee313d2SEric Christopher; PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}3)
9cee313d2SEric Christopherbb:
10cee313d2SEric Christopher  %tmp = add nsw i32 %n, 1
11cee313d2SEric Christopher  %tmp1 = add nsw i32 %n, -1
12cee313d2SEric Christopher  br label %bb2
13cee313d2SEric Christopher
14cee313d2SEric Christopherbb2:                                              ; preds = %bb9, %bb
15cee313d2SEric Christopher; PROMO: phi {{.*}}
16cee313d2SEric Christopher; PROMO-NEXT: phi {{.*}}
17cee313d2SEric Christopher; PROMO-NEXT: phi {{.*}}
18cee313d2SEric Christopher; PROMO-NEXT: phi {{.*}}
19cee313d2SEric Christopher  %i.0 = phi i32 [ 0, %bb ], [ %tmp10, %bb9 ]
20cee313d2SEric Christopher  %tmp3 = icmp slt i32 %i.0, %tmp
21cee313d2SEric Christopher  br i1 %tmp3, label %bb4, label %bb5
22cee313d2SEric Christopher
23cee313d2SEric Christopherbb4:                                              ; preds = %bb2
24cee313d2SEric Christopher  tail call void @bar(i32 1)
25cee313d2SEric Christopher  br label %bb9
26cee313d2SEric Christopher
27cee313d2SEric Christopherbb5:                                              ; preds = %bb2
28cee313d2SEric Christopher  %tmp6 = icmp slt i32 %i.0, %tmp1
29cee313d2SEric Christopher  br i1 %tmp6, label %bb7, label %bb8
30cee313d2SEric Christopher
31cee313d2SEric Christopherbb7:                                              ; preds = %bb5
32cee313d2SEric Christopher  tail call void @bar(i32 2)
33cee313d2SEric Christopher  br label %bb9
34cee313d2SEric Christopher
35cee313d2SEric Christopherbb8:                                              ; preds = %bb5
36cee313d2SEric Christopher  tail call void @bar(i32 3)
37cee313d2SEric Christopher  br label %bb9
38cee313d2SEric Christopher
39cee313d2SEric Christopherbb9:                                              ; preds = %bb8, %bb7, %bb4
40cee313d2SEric Christopher; PROMO: %[[LIVEOUT3:[a-z0-9]+]] = phi {{.*}}
41cee313d2SEric Christopher; PROMO-NEXT: %[[LIVEOUT2:[a-z0-9]+]] = phi {{.*}}
42cee313d2SEric Christopher; PROMO-NEXT: %[[LIVEOUT1:[a-z0-9]+]] = phi {{.*}}
43cee313d2SEric Christopher  %tmp10 = add nsw i32 %i.0, 1
44cee313d2SEric Christopher  %tmp11 = icmp slt i32 %tmp10, %N
45cee313d2SEric Christopher  br i1 %tmp11, label %bb2, label %bb12
46cee313d2SEric Christopher
47cee313d2SEric Christopherbb12:                                             ; preds = %bb9
48cee313d2SEric Christopher  ret void
49*41d5033eSNikita Popov; NONATOMIC_PROMO: %[[PROMO1:[a-z0-9.]+]] = load {{.*}} @__profc_foo{{.*}}
50cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: add {{.*}} %[[PROMO1]], %[[LIVEOUT1]]
51*41d5033eSNikita Popov; NONATOMIC_PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}
52cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: %[[PROMO2:[a-z0-9.]+]] = load {{.*}} @__profc_foo{{.*}} 1)
53cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: add {{.*}} %[[PROMO2]], %[[LIVEOUT2]]
54cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}1)
55cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: %[[PROMO3:[a-z0-9.]+]] = load {{.*}} @__profc_foo{{.*}} 2)
56cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: add {{.*}} %[[PROMO3]], %[[LIVEOUT3]]
57cee313d2SEric Christopher; NONATOMIC_PROMO-NEXT: store {{.*}}@__profc_foo{{.*}}2)
58*41d5033eSNikita Popov; ATOMIC_PROMO: atomicrmw add {{.*}} @__profc_foo{{.*}}, i64 %[[LIVEOUT1]] seq_cst
59cee313d2SEric Christopher; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}1), i64 %[[LIVEOUT2]] seq_cst
60cee313d2SEric Christopher; ATOMIC_PROMO-NEXT: atomicrmw add {{.*}} @__profc_foo{{.*}}2), i64 %[[LIVEOUT3]] seq_cst
61c24b7a16SPetr Hosek; PROMO-NOT: @__profc_foo{{.*}})
62cee313d2SEric Christopher
63cee313d2SEric Christopher
64cee313d2SEric Christopher}
65cee313d2SEric Christopher
66cee313d2SEric Christopherdeclare void @bar(i32)
67