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: "rguenther at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 04 Jul 2016 11:03:07 +0000
- Subject: [Bug middle-end/70159] missed CSE optimization
- Auto-submitted: auto-generated
- References: <bug-70159-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70159
--- Comment #12 from rguenther at suse dot de <rguenther at suse dot de> ---
On Sat, 2 Jul 2016, hiraditya at msn dot com wrote:
> 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
> }
Same if you forward-port the patch from PR23286 (just did that).
> cat t.c.126t.pre
...
foo_p (float d, float min, float max, float a)
{
float inv;
float tmax;
float tmin;
float _16;
float _18;
float _19;
float _20;
float _21;
<bb 2>:
inv_8 = 1.0e+0 / d_7(D);
_18 = min_9(D) - a_10(D);
_19 = inv_8 * _18;
_20 = max_12(D) - a_10(D);
_21 = inv_8 * _20;
if (inv_8 >= 0.0)
goto <bb 4>;
else
goto <bb 3>;
<bb 3>:
<bb 4>:
# tmin_5 = PHI <_19(2), _21(3)>
# tmax_6 = PHI <_21(2), _19(3)>
_16 = tmin_5 + tmax_6;
return _16;