[Bug target/107174] [ARM] Wrong opcodes *.f64.s32 (signed) in conversion [unsigned ->double] with -O2

2022-10-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107174

--- Comment #2 from Andrew Pinski  ---
 -fsanitize=undefined catches this at runtime:
/app/example.cpp:10:28: runtime error: signed integer overflow: 20 -
-10 cannot be represented in type 'int'
/app/example.cpp:7:28: runtime error: signed integer overflow: 20 -
-10 cannot be represented in type 'int'

[Bug target/107174] [ARM] Wrong opcodes *.f64.s32 (signed) in conversion [unsigned ->double] with -O2

2022-10-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107174

Andrew Pinski  changed:

   What|Removed |Added

 Resolution|--- |INVALID
 Status|UNCONFIRMED |RESOLVED

--- Comment #1 from Andrew Pinski  ---
There is no bug here as signed integer overflow is undefined.
You should do the following if you want unsigned conversion.


__attribute__((noinline)) double deltaToDouble(int a, int b) {
  unsigned ua = a;
  unsigned ub = b;
  if (a < b) {
unsigned int delta = ub - ua;
return -((double)delta);
  } else {
unsigned int delta = ua - ub;
return (double)delta;
  }
}

Otherwise GCC will assume (a - b) and (b - a) will never be overflow (as it is
undefined) and you will get the signed coversions.