1 ; RUN: opt -gvn-hoist -S < %s | FileCheck %s
3 ; Check that convergent calls are not hoisted.
5 ; CHECK-LABEL: @no_convergent_func_hoisting(
7 ; CHECK: call float @convergent_func(
10 ; CHECK: call float @convergent_func(
11 define float @no_convergent_func_hoisting(float %d, float %min, float %max, float %a) {
13 %div = fdiv float 1.000000e+00, %d
14 %cmp = fcmp oge float %div, 0.000000e+00
15 br i1 %cmp, label %if.then, label %if.else
18 %sub1 = fsub float %max, %a
19 %mul2 = call float @convergent_func(float %sub1, float %div)
23 %sub5 = fsub float %max, %a
24 %mul6 = call float @convergent_func(float %sub5, float %div)
28 %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
29 %add = fadd float %tmax.0, 10.0
33 ; The call site is convergent but the declaration is not.
34 ; CHECK-LABEL: @no_convergent_call_hoisting(
37 ; CHECK: call float @func(
40 ; CHECK: call float @func(
41 define float @no_convergent_call_hoisting(float %d, float %min, float %max, float %a) {
43 %div = fdiv float 1.000000e+00, %d
44 %cmp = fcmp oge float %div, 0.000000e+00
45 br i1 %cmp, label %if.then, label %if.else
48 %sub1 = fsub float %max, %a
49 %mul2 = call float @func(float %sub1, float %div) #0
53 %sub5 = fsub float %max, %a
54 %mul6 = call float @func(float %sub5, float %div) #0
58 %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
59 %add = fadd float %tmax.0, 10.0
63 ; The call site is convergent but the declaration is not.
64 ; CHECK-LABEL: @call_hoisting(
65 ; CHECK: call float @func(
66 ; CHECK-NOT: call float @func(
67 define float @call_hoisting(float %d, float %min, float %max, float %a) {
69 %div = fdiv float 1.000000e+00, %d
70 %cmp = fcmp oge float %div, 0.000000e+00
71 br i1 %cmp, label %if.then, label %if.else
74 %sub1 = fsub float %max, %a
75 %mul2 = call float @func(float %sub1, float %div)
79 %sub5 = fsub float %max, %a
80 %mul6 = call float @func(float %sub5, float %div)
84 %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
85 %add = fadd float %tmax.0, 10.0
89 declare float @convergent_func(float, float) #0
90 declare float @func(float, float) #1
92 attributes #0 = { nounwind readnone convergent willreturn }
93 attributes #1 = { nounwind readnone willreturn }