[Bug target/110182] Vector(2) cast from double to float and subtraction seems to produce incorrect results at -O2 and above

2023-06-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110182

--- Comment #2 from Andrew Pinski  ---
>but not -O3.

Oh that is because the vectorizer is not enabled at -O2 in GCC 11 but is for
GCC 12+.

[Bug target/110182] Vector(2) cast from double to float and subtraction seems to produce incorrect results at -O2 and above

2023-06-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110182

Andrew Pinski  changed:

   What|Removed |Added

  Component|c++ |target
Summary|GCC generates incorrect |Vector(2) cast from double
   |results for simple Eigen|to float and subtraction
   |Casts / Subtractions at -O2 |seems to produce incorrect
   |or above for a 3|results at -O2 and above
   |dimensional vector  |

--- Comment #1 from Andrew Pinski  ---
Looks like a target issue:
The gimple level looks like this in GCC 12 for low:
  vect__178.810_465 = (vector(2) float) _165;
  vect__202.814_467 = _165 - _165;
  vect__203.815_466 = (vector(2) float) vect__202.814_467;
  _172 = SR.808_30 * 6.371e+6;
  MEM[(struct plain_array *)] ={v} {CLOBBER};
  MEM  [(float &)] = vect__178.810_465;
  _184 = (float) _172;
  MEM[(float &) + 8] = _184;
  MEM[(struct plain_array *)] ={v} {CLOBBER};
  MEM  [(float &)] = vect__203.815_466;


While for GCC 11 we have the casting as scalar:
  _173 = (float) _298;
  MEM[(float &)] = _173;
  _296 = BIT_FIELD_REF <_160, 64, 64>;
  _177 = (float) _296;
  MEM[(float &) + 4] = _177;
  _179 = (float) _167;
  MEM[(float &) + 8] = _179;
  MEM[(struct plain_array *)] ={v} {CLOBBER};
  _192 = (double) _173;
  _197 = _298 - _192;
  _198 = (float) _197;
  MEM[(float &)] = _198;
  _224 = (double) _177;
  _229 = _296 - _224;
  _230 = (float) _229;
  MEM[(float &) + 4] = _230;
  _208 = (double) _179;
  _213 = _167 - _208;
  _214 = (float) _213;
  MEM[(float &) + 8] = _214;