[Bug target/114659] gcc miscompiles a __builtin_memcpy on i386, leading to wrong results for SNaN

2024-04-09 Thread bruno at clisp dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659

--- Comment #9 from Bruno Haible  ---
(In reply to Andrew Pinski from comment #7)
> Much more related to PR 56831 and PR 57484 rather than the other two ...

Well, bug #56831 is more about function calls and the ABI, whereas this bug
here and bug #58416 and bug #93271 are about the compiler picking a memory
location which holds convert_snan_to_qnan(value) rather than a memory location
which holds the original value.

[Bug target/114659] gcc miscompiles a __builtin_memcpy on i386, leading to wrong results for SNaN

2024-04-09 Thread bruno at clisp dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659

--- Comment #8 from Bruno Haible  ---
(In reply to Andrew Pinski from comment #6)
> I doubt there is not much to be done here.

I see it as an incorrect modelization of the x87 hardware, together with a
missing distinction in the common expression elimination / aliasing analysis.
In detail:

* Incorrect modelization of the x87 hardware: The compiler seems to assume that
flds MEM_LOCATION_1
fsts MEM_LOCATION_2
  will result in MEM_LOCATION_2 having the same value as MEM_LOCATION_1. This
is wrong;
  this is not how the x87 hardware behaves. The actual result is:
*MEM_LOCATION_2 = convert_snan_to_qnan(*MEM_LOCATION_1).

* In the common expression elimination / aliasing analysis, the compilers seems
to keep
  track of a set of memory locations MEM_LOCATION_1, ..., MEM_LOCATION_n which
have the
  same value. In fact, this set needs to be partitioned into two sets: a subset
which
  contains the same value, and the complementary subset which contains
  convert_snan_to_qnan(value).

  In other words, each element of the set needs to be annotated with a bit that
tells
  whether the value has been subject to the convert_snan_to_qnan.

[Bug target/114659] gcc miscompiles a __builtin_memcpy on i386, leading to wrong results for SNaN

2024-04-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659

Andrew Pinski  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=56831,
   ||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=57484

--- Comment #7 from Andrew Pinski  ---
Much more related to PR 56831 and PR 57484 rather than the other two ...

[Bug target/114659] gcc miscompiles a __builtin_memcpy on i386, leading to wrong results for SNaN

2024-04-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114659

Andrew Pinski  changed:

   What|Removed |Added

  Component|middle-end  |target

--- Comment #6 from Andrew Pinski  ---
I doubt there is not much to be done here. It is a x87 issue where we do the
store of the float register stack register to the stack to get 32bits (or
64bit) version. And then load it into a GPR.




  float t = *x;
  float t1 = *y;

 __builtin_memcpy (, , sizeof (float));
 __builtin_memcpy (, , sizeof (float));

Produces exactly the same issue.