94 lines · plain
1; RUN: opt -passes=gvn-hoist -S < %s | FileCheck %s2 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, %d14 %cmp = fcmp oge float %div, 0.000000e+0015 br i1 %cmp, label %if.then, label %if.else16 17if.then:18 %sub1 = fsub float %max, %a19 %mul2 = call float @convergent_func(float %sub1, float %div)20 br label %if.end21 22if.else:23 %sub5 = fsub float %max, %a24 %mul6 = call float @convergent_func(float %sub5, float %div)25 br label %if.end26 27if.end:28 %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]29 %add = fadd float %tmax.0, 10.030 ret float %add31}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, %d44 %cmp = fcmp oge float %div, 0.000000e+0045 br i1 %cmp, label %if.then, label %if.else46 47if.then:48 %sub1 = fsub float %max, %a49 %mul2 = call float @func(float %sub1, float %div) #050 br label %if.end51 52if.else:53 %sub5 = fsub float %max, %a54 %mul6 = call float @func(float %sub5, float %div) #055 br label %if.end56 57if.end:58 %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]59 %add = fadd float %tmax.0, 10.060 ret float %add61}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, %d70 %cmp = fcmp oge float %div, 0.000000e+0071 br i1 %cmp, label %if.then, label %if.else72 73if.then:74 %sub1 = fsub float %max, %a75 %mul2 = call float @func(float %sub1, float %div)76 br label %if.end77 78if.else:79 %sub5 = fsub float %max, %a80 %mul6 = call float @func(float %sub5, float %div)81 br label %if.end82 83if.end:84 %tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]85 %add = fadd float %tmax.0, 10.086 ret float %add87}88 89declare float @convergent_func(float, float) #090declare float @func(float, float) #191 92attributes #0 = { nounwind readnone convergent willreturn }93attributes #1 = { nounwind readnone willreturn }94