This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/70159] missed CSE optimization
- From: "hiraditya at msn dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 02 Jul 2016 14:24:19 +0000
- Subject: [Bug middle-end/70159] missed CSE optimization
- Auto-submitted: auto-generated
- References: <bug-70159-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70159
AK <hiraditya at msn dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hiraditya at msn dot com
--- Comment #11 from AK <hiraditya at msn dot com> ---
Just as an update, the new gvn-hoist pass in llvm hoists the common
computations:
@cat test.c
float foo_p(float d, float min, float max, float a)
{
float tmin;
float tmax;
float inv = 1.0f / d;
if (inv >= 0) {
tmin = (min - a) * inv;
tmax = (max - a) * inv;
} else {
tmin = (max - a) * inv;
tmax = (min - a) * inv;
}
return tmax + tmin;
}
clang -c -Ofast test.c -mllvm -print-after-all
*** IR Dump Before Early GVN Hoisting of Expressions ***
; Function Attrs: nounwind uwtable
define float @_Z5foo_pffff(float %d, float %min, float %max, float %a) #0 {
entry:
%div = fdiv fast float 1.000000e+00, %d
%cmp = fcmp fast oge float %div, 0.000000e+00
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
%sub = fsub fast float %min, %a
%mul = fmul fast float %sub, %div
%sub1 = fsub fast float %max, %a
%mul2 = fmul fast float %sub1, %div
br label %if.end
if.else: ; preds = %entry
%sub3 = fsub fast float %max, %a
%mul4 = fmul fast float %sub3, %div
%sub5 = fsub fast float %min, %a
%mul6 = fmul fast float %sub5, %div
br label %if.end
if.end: ; preds = %if.else, %if.then
%tmax.0 = phi float [ %mul2, %if.then ], [ %mul6, %if.else ]
%tmin.0 = phi float [ %mul, %if.then ], [ %mul4, %if.else ]
%add = fadd fast float %tmax.0, %tmin.0
ret float %add
}
*** IR Dump After Early GVN Hoisting of Expressions ***
; Function Attrs: nounwind uwtable
define float @_Z5foo_pffff(float %d, float %min, float %max, float %a) #0 {
entry:
%div = fdiv fast float 1.000000e+00, %d
%cmp = fcmp fast oge float %div, 0.000000e+00
%sub = fsub fast float %min, %a
%mul = fmul fast float %sub, %div
%sub1 = fsub fast float %max, %a
%mul2 = fmul fast float %sub1, %div
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
br label %if.end
if.else: ; preds = %entry
br label %if.end
if.end: ; preds = %if.else, %if.then
%tmax.0 = phi float [ %mul2, %if.then ], [ %mul, %if.else ]
%tmin.0 = phi float [ %mul, %if.then ], [ %mul2, %if.else ]
%add = fadd fast float %tmax.0, %tmin.0
ret float %add
}