[Bug target/86947] Erroneous code generated with O2 and O3 for PPC

2018-08-23 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86947

Richard Biener  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 Resolution|--- |INVALID

--- Comment #5 from Richard Biener  ---
Thanks.  This is invalid:

unsigned short *_Pmsw (double * px)
{
volatile _Dconst *ps = (_Dconst *)(char *)px;
return (unsigned short *)>_Word[3];
}

  if (x < 0.0)
{
  ((*_Pmsw (&(x))) ^= ((unsigned short) 0x8000));
  neg = 1;
}
  else
neg = 0;

  /* _Eps._Double = 1.0 */
  /* aliasing issue here. Compiler uses old value of x */
  if (x < _Eps._Double) {

the compiler can CSE the value of x across the *_Pmsw () modification
because

 1) the load from x via an lvalue of type unsigned short violates type
based aliasing rules
 2) the store to x via an lvalue of type unsigned short changes the dynamic
type of x which in turn makes the later load of x violate type based
aliasing rules

You can use -fno-strict-aliasing to make your code work.  You might think
that having the _Dconst union in scope makes your program conforming but
GCC does not implement this reading of the standard unless you use
-fno-strict-aliasing which is not the default when optimizing with -O2
or higher.

[Bug target/86947] Erroneous code generated with O2 and O3 for PPC

2018-08-22 Thread vinay.m.engg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86947

--- Comment #4 from Vinay Kumar  ---
Hi Richard,

Thanks for checking the bug.
Please find attached the testcase that would exit with message
"Should NOT BE here" on miscompilation.

The behavior is same with other targets as well.
We have checked it with latest X86 and Aarch64 targets.

gcc t1.c t2.c -O2 -m64 -lm

[Bug target/86947] Erroneous code generated with O2 and O3 for PPC

2018-08-22 Thread vinay.m.engg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86947

--- Comment #3 from Vinay Kumar  ---
Created attachment 44572
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44572=edit
Testcase t2.c

[Bug target/86947] Erroneous code generated with O2 and O3 for PPC

2018-08-22 Thread vinay.m.engg at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86947

Vinay Kumar  changed:

   What|Removed |Added

 CC||vinay.m.engg at gmail dot com

--- Comment #2 from Vinay Kumar  ---
Created attachment 44571
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44571=edit
Testcase t1.c

[Bug target/86947] Erroneous code generated with O2 and O3 for PPC

2018-08-22 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86947

Richard Biener  changed:

   What|Removed |Added

 Target||powerpc
 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2018-08-22
 CC||rguenth at gcc dot gnu.org
  Component|c   |target
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
Can you possibly provide a driver (main() function) that calls abort() when
the miscompilation occurs and exits without error if not?