• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -gvn-hoist -S < %s | FileCheck %s
2
3; Check that convergent calls are not hoisted.
4;
5; CHECK-LABEL: @no_convergent_func_hoisting(
6; CHECK: if.then:
7; CHECK: call float @convergent_func(
8
9; CHECK: if.else:
10; CHECK: call float @convergent_func(
11define float @no_convergent_func_hoisting(float %d, float %min, float %max, float %a) {
12entry:
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
16
17if.then:
18  %sub1 = fsub float %max, %a
19  %mul2 = call float @convergent_func(float %sub1, float %div)
20  br label %if.end
21
22if.else:
23  %sub5 = fsub float %max, %a
24  %mul6 = call float @convergent_func(float %sub5, float %div)
25  br label %if.end
26
27if.end:
28  %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
29  %add = fadd float %tmax.0, 10.0
30  ret float %add
31}
32
33; The call site is convergent but the declaration is not.
34; CHECK-LABEL: @no_convergent_call_hoisting(
35
36; CHECK: if.then:
37; CHECK: call float @func(
38
39; CHECK: if.else:
40; CHECK: call float @func(
41define float @no_convergent_call_hoisting(float %d, float %min, float %max, float %a) {
42entry:
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
46
47if.then:
48  %sub1 = fsub float %max, %a
49  %mul2 = call float @func(float %sub1, float %div) #0
50  br label %if.end
51
52if.else:
53  %sub5 = fsub float %max, %a
54  %mul6 = call float @func(float %sub5, float %div) #0
55  br label %if.end
56
57if.end:
58  %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
59  %add = fadd float %tmax.0, 10.0
60  ret float %add
61}
62
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(
67define float @call_hoisting(float %d, float %min, float %max, float %a) {
68entry:
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
72
73if.then:
74  %sub1 = fsub float %max, %a
75  %mul2 = call float @func(float %sub1, float %div)
76  br label %if.end
77
78if.else:
79  %sub5 = fsub float %max, %a
80  %mul6 = call float @func(float %sub5, float %div)
81  br label %if.end
82
83if.end:
84  %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
85  %add = fadd float %tmax.0, 10.0
86  ret float %add
87}
88
89declare float @convergent_func(float, float) #0
90declare float @func(float, float) #1
91
92attributes #0 = { nounwind readnone convergent }
93attributes #1 = { nounwind readnone }
94