[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-12-08 Thread slyfox at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

--- Comment #12 from Sergei Trofimovich  ---
(In reply to Jakub Jelinek from comment #5)
> It is the foperator_mult::op{1,2}_range and can be seen even on:
> double
> foo (double x, double y)
> {
>   double z = x * y;
>   if (z == 0.0)
> return x;
>   return 42.0;
> }
> testcase.
> 2->3  (T) x_2(D) :  [frange] double [-0.0 (-0x0.0p+0), 0.0 (0x0.0p+0)]
> 2->3  (T) y_3(D) :  [frange] double [-0.0 (-0x0.0p+0), 0.0 (0x0.0p+0)]
> 2->3  (T) z_4 : [frange] double [-0.0 (-0x0.0p+0), 0.0 (0x0.0p+0)]
> On the true edge of z == 0.0, we have [-0., 0.] range for z_4, that is

For my curiosity fow did you get such a detailed [frange] output for the
expressions? I tried -fdump-tree-all-all and best I get is a one-liner around
PHI nodes:

  # RANGE [frange] double [0.0 (0x0.0p+0), +Inf]
  # iftmp.5_6 = PHI 
  # .MEM_23 = PHI <.MEM_19(3), .MEM_19(4), .MEM_15(6)>
  # VUSE <.MEM_23>
  return iftmp.5_6;

Is there a magic gcc flag to dump more range details? Or you had to patch a bit
of gcc code?

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-12-05 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

--- Comment #11 from Martin Liška  ---
> I was sure the
> server-side receive hook was supposed to reject such incomplete Changelog,
> though?

New files in test-suite are not mandatory by the hook and corresponding
ChangeLog entries are generated automatically.

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-12-05 Thread amonakov at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

--- Comment #10 from Alexander Monakov  ---
If anyone is confused like I was, the commit actually includes a testcase, but
the addition is not mentioned in the Changelog. I was sure the server-side
receive hook was supposed to reject such incomplete Changelog, though?

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-12-05 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Jakub Jelinek  ---
Fixed.

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-12-05 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

--- Comment #8 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:4500baaccb6e4d696e223c338bbdf7705c3646dd

commit r13-4492-g4500baaccb6e4d696e223c338bbdf7705c3646dd
Author: Jakub Jelinek 
Date:   Mon Dec 5 11:17:42 2022 +0100

range-op-float: Fix up multiplication and division reverse operation
[PR107879]

While for the normal cases it seems to be correct to implement
reverse multiplication (op1_range/op2_range) through division
with float_binary_op_range_finish, reverse division (op1_range)
through multiplication with float_binary_op_range_finish or
(op2_range) through division with float_binary_op_range_finish,
as e.g. following testcase shows for the corner cases it is
incorrect.
Say on the testcase we are doing reverse multiplication, we
have [-0., 0.] range (no NAN) on lhs and VARYING on op1 (or op2).
We implement that through division, because x from
lhs = x * op2
is
x = lhs / op2
For the division, [-0., 0.] / VARYING is computed (IMHO correctly)
as [-0., 0.] +-NAN, because 0 / anything but 0 or NAN is still
0 and 0 / 0 is NAN and ditto 0 / NAN.  And then we just
float_binary_op_range_finish, which figures out that because lhs
can't be NAN, neither operand can be NAN.  So, the end range is
[-0., 0.].  But that is not correct for the reverse multiplication.
When the result is 0, if op2 can be zero, then x can be anything
(VARYING), to be precise anything but INF (unless result can be NAN),
because anything * 0 is 0 (or NAN for INF).  While if op2 must be
non-zero, then x must be 0.  Of course the sign logic
(signbit(x) = signbit(lhs) ^ signbit(op2)) still holds, so it actually
isn't full VARYING if both lhs and op2 have known sign bits.
And going through other corner cases one by one shows other differences
between what we compute for the corresponding forward operation and
what we should compute for the reverse operations.
The following patch is slightly conservative and includes INF
(in case of result including 0 and not NAN) in the ranges or
0 in the ranges (in case of result including INF and not NAN).
The latter is what happens anyway because we flush denormals to 0,
and the former just not to deal with all the corner cases.
So, the end test is that for reverse multiplication and division
op2_range the cases we need to adjust to VARYING or VARYING positive
or VARYING negative are if lhs and op? ranges both contain 0,
or both contain some infinity, while for division op1_range the
corner case is if lhs range contains 0 and op2 range contains INF or vice
versa.  Otherwise I believe ranges from the corresponding operation
are ok, or could be slightly more conservative (e.g. for
reverse multiplication, if op? range is singleton INF and lhs
range doesn't include any INF, then x's range should be UNDEFINED or
known NAN (depending on if lhs can be NAN), while the division computes
[-0., 0.] +-NAN; or similarly if op? range is only 0 and lhs range
doesn't include 0, division would compute +INF +-NAN, or -INF +-NAN,
or (for lack of multipart franges -INF +INF +-NAN just VARYING +-NAN),
while again it is UNDEFINED or known NAN.

Oh, and I found by code inspection wrong condition for the division's
known NAN result, due to thinko it would trigger not just when
both operands are known to be 0 or both are known to be INF, but
when either both are known to be 0, or at least one is known to be INF.

2022-12-05  Jakub Jelinek  

PR tree-optimization/107879
* range-op-float.cc (foperator_mult::op1_range): If both
lhs and op2 ranges contain zero or both ranges contain
some infinity, set r range to zero_to_inf_range depending on
signbit_known_p.
(foperator_div::op2_range): Similarly for lhs and op1 ranges.
(foperator_div::op1_range): If lhs range contains zero and op2
range contains some infinity or vice versa, set r range to
zero_to_inf_range depending on signbit_known_p.
(foperator_div::rv_fold): Fix up condition for returning known NAN.

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-28 Thread slyfox at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

--- Comment #7 from Sergei Trofimovich  ---
(In reply to Jakub Jelinek from comment #6)
> Created attachment 53978 [details]
> gcc13-pr107879.patch
> 
> Untested fix.

The patch fixed real ffmpeg-4 tests for me (before the change there were about
10 failures in resampler). Thank you!

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-28 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

Jakub Jelinek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
 Status|NEW |ASSIGNED

--- Comment #6 from Jakub Jelinek  ---
Created attachment 53978
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53978=edit
gcc13-pr107879.patch

Untested fix.

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-28 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

--- Comment #5 from Jakub Jelinek  ---
It is the foperator_mult::op{1,2}_range and can be seen even on:
double
foo (double x, double y)
{
  double z = x * y;
  if (z == 0.0)
return x;
  return 42.0;
}
testcase.
2->3  (T) x_2(D) :  [frange] double [-0.0 (-0x0.0p+0), 0.0 (0x0.0p+0)]
2->3  (T) y_3(D) :  [frange] double [-0.0 (-0x0.0p+0), 0.0 (0x0.0p+0)]
2->3  (T) z_4 : [frange] double [-0.0 (-0x0.0p+0), 0.0 (0x0.0p+0)]
On the true edge of z == 0.0, we have [-0., 0.] range for z_4, that is correct,
but getting from lhs [-0., 0.] and op2 range VARYING to [-0., 0.] is wrong.
We get that because we compute the range in that case as [-0., 0.] / VARYING,
and for division it is actually correct, [-0., 0.] divided by anything non-NAN
non-zero is still [-0., 0.], and [-0., 0.] divided by [-0., 0.] is NAN.
Plus we have the (IMHO still correct) implication that if a result is not NAN,
then neither operand could be NAN.

So I'm afraid back to the drawing board on when we can use division for
multiplication reverse ranges and when we can use multiplication for division
reverse ranges (and whether it is ok to use minus/plus for plus/minus reverse
operations).

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-28 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek  ---
I will have a look.

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-27 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P1

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-26 Thread slyfox at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

Sergei Trofimovich  changed:

   What|Removed |Added

 CC||jakub at redhat dot com

--- Comment #3 from Sergei Trofimovich  ---
If I did the bisection correctly `git bisect` points to
r13-3926-gd4c2f1d376da6f

commit d4c2f1d376da6fc3f3c30a9d3160e43c95399343
Author: Jakub Jelinek 
Date:   Sat Nov 12 09:39:00 2022 +0100

range-op: Implement op[12]_range operators for {PLUS,MINUS,MULT,RDIV}_EXPR

[Bug tree-optimization/107879] [13 Regression] ffmpeg-4 test suite fails on FPU arithmetics

2022-11-26 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107879

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||wrong-code
   Target Milestone|--- |13.0
 CC||aldyh at gcc dot gnu.org
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2022-11-26
 Ever confirmed|0   |1
  Component|middle-end  |tree-optimization

--- Comment #2 from Andrew Pinski  ---
.