1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2
2 ; RUN: opt < %s -passes='simplifycfg<no-sink-common-insts;hoist-common-insts>' -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s --check-prefix=HOIST
4 ; Test case based on C++ code with manualy annotated !prof metadata.
5 ; This is to test that when calls to 'func1' from 'if.then' block
6 ; and 'if.else' block are hoisted, the branch_weights are merged and
7 ; attached to merged call rather than dropped.
9 ; int func1(int a, int b) ;
10 ; int func2(int a, int b) ;
12 ; int func(int a, int b, bool c) {
22 define i32 @_Z4funciib(i32 %a, i32 %b, i1 %c) {
23 ; HOIST-LABEL: define i32 @_Z4funciib
24 ; HOIST-SAME: (i32 [[A:%.*]], i32 [[B:%.*]], i1 [[C:%.*]]) {
26 ; HOIST-NEXT: [[CALL:%.*]] = tail call i32 @_Z5func1ii(i32 [[A]], i32 [[B]]), !prof [[PROF0:![0-9]+]]
27 ; HOIST-NEXT: br i1 [[C]], label [[IF_END:%.*]], label [[IF_ELSE:%.*]]
29 ; HOIST-NEXT: [[CALL3:%.*]] = tail call i32 @_Z5func2ii(i32 [[A]], i32 [[B]])
30 ; HOIST-NEXT: [[SUB:%.*]] = sub i32 [[CALL]], [[CALL3]]
31 ; HOIST-NEXT: br label [[IF_END]]
33 ; HOIST-NEXT: [[SUM_0:%.*]] = phi i32 [ [[SUB]], [[IF_ELSE]] ], [ [[CALL]], [[ENTRY:%.*]] ]
34 ; HOIST-NEXT: ret i32 [[SUM_0]]
37 br i1 %c, label %if.then, label %if.else
39 if.then: ; preds = %entry
40 %call = tail call i32 @_Z5func1ii(i32 %a, i32 %b), !prof !0
43 if.else: ; preds = %entry
44 %call1 = tail call i32 @_Z5func1ii(i32 %a, i32 %b), !prof !1
45 %call3 = tail call i32 @_Z5func2ii(i32 %a, i32 %b)
46 %sub = sub i32 %call1, %call3
49 if.end: ; preds = %if.else, %if.then
50 %sum.0 = phi i32 [ %call, %if.then ], [ %sub, %if.else ]
54 declare i32 @_Z5func1ii(i32, i32)
56 declare i32 @_Z5func2ii(i32, i32)
58 !0 = !{!"branch_weights", i32 10}
59 !1 = !{!"branch_weights", i32 90}
61 ; HOIST: [[PROF0]] = !{!"branch_weights", i64 100}