https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69726

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic,
                   |                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-02-09
                 CC|                            |rguenth at gcc dot gnu.org
            Summary|Bogus warnings with -O3     |Bogus warnings with -O3
                   |-Wuninitialized             |-Wuninitialized because of
                   |                            |if-conversion
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
So at uninit time we have

  <bb 2>:
  vect__117.6_137 = MEM[(const int32_t *)block_8(D) + 32B];
  vect__118.9_138 = MEM[(const int32_t *)block_8(D) + 64B];
  vect__119.10_139 = vect__117.6_137 | vect__118.9_138;
  vect__120.13_140 = MEM[(const int32_t *)block_8(D) + 96B];
  vect__121.14_141 = vect__119.10_139 | vect__120.13_140;
  vect__122.17_142 = MEM[(const int32_t *)block_8(D) + 128B];
  vect__123.18_143 = vect__121.14_141 | vect__122.17_142;
  vect__124.21_144 = MEM[(const int32_t *)block_8(D) + 160B];
  vect__125.22_145 = vect__123.18_143 | vect__124.21_144;
  vect__126.25_146 = MEM[(const int32_t *)block_8(D) + 192B];
  vect__127.26_147 = vect__125.22_145 | vect__126.25_146;
  vect__128.29_148 = MEM[(const int32_t *)block_8(D) + 224B];
  vect__129.30_149 = vect__127.26_147 | vect__128.29_148;
  vect__130.33_150 = MEM[(const int32_t *)block_8(D)];
  vect__ifc__525.36_152 = MEM[(int *)&temp + 224B];
  vect__ifc__523.38_154 = VEC_COND_EXPR <vect__129.30_149 == { 0, 0, 0, 0 },
vect__130.33_150, vect__ifc__525.36_152>;
  vect__ifc__522.43_157 = MEM[(int *)&temp + 192B];
  vect__ifc__520.45_159 = VEC_COND_EXPR <vect__129.30_149 == { 0, 0, 0, 0 },
vect__130.33_150, vect__ifc__522.43_157>;
  vect__ifc__519.50_499 = MEM[(int *)&temp + 160B];
  vect__ifc__517.52_161 = VEC_COND_EXPR <vect__129.30_149 == { 0, 0, 0, 0 },
vect__130.33_150, vect__ifc__519.50_499>;
  vect__ifc__516.57_497 = MEM[(int *)&temp + 128B];
  vect__ifc__514.59_163 = VEC_COND_EXPR <vect__129.30_149 == { 0, 0, 0, 0 },
vect__130.33_150, vect__ifc__516.57_497>;
  vect__ifc__513.64_495 = MEM[(int *)&temp + 96B];
  vect__ifc__511.66_493 = VEC_COND_EXPR <vect__129.30_149 == { 0, 0, 0, 0 },
vect__130.33_150, vect__ifc__513.64_495>;
  vect__ifc__510.71_492 = MEM[(int *)&temp + 64B];
  vect__ifc__508.73_486 = VEC_COND_EXPR <vect__129.30_149 == { 0, 0, 0, 0 },
vect__130.33_150, vect__ifc__510.71_492>;
  vect__ifc__507.78_484 = MEM[(int *)&temp + 32B];
...

which means they are used conditional on vect__129.30_149 != { 0, 0, 0, 0 }.

But temp itself is never initialized.

This is caused by if-conversion which transforms

  <bb 3>:
  # i_199 = PHI <i_12(7), 0(2)>
  # ivtmp_624 = PHI <ivtmp_623(7), 8(2)>
  _6 = (long unsigned int) i_199;
  _7 = _6 * 4;
  _9 = block_8(D) + _7;
  _10 = &temp + _7;
  _117 = MEM[(const int32_t *)_9 + 32B];
  _118 = MEM[(const int32_t *)_9 + 64B];
  _119 = _117 | _118;
  _120 = MEM[(const int32_t *)_9 + 96B];
  _121 = _119 | _120;
  _122 = MEM[(const int32_t *)_9 + 128B];
  _123 = _121 | _122;
  _124 = MEM[(const int32_t *)_9 + 160B];
  _125 = _123 | _124;
  _126 = MEM[(const int32_t *)_9 + 192B];
  _127 = _125 | _126;
  _128 = MEM[(const int32_t *)_9 + 224B];
  _129 = _127 | _128;
  if (_129 == 0)
    goto <bb 4>;
  else
    goto <bb 5>;

  <bb 4>:
  _130 = MEM[(const int32_t *)_9];
  MEM[(int *)_10 + 224B] = _130;
  MEM[(int *)_10 + 192B] = _130;
  MEM[(int *)_10 + 160B] = _130;
  MEM[(int *)_10 + 128B] = _130;
  MEM[(int *)_10 + 96B] = _130;
  MEM[(int *)_10 + 64B] = _130;
  MEM[(int *)_10 + 32B] = _130;
  MEM[(int *)&temp][i_199] = _130;
  goto <bb 6>;

  <bb 5>:
  _131 = MEM[(const int32_t *)_9];
  a0_132 = _122 + _131;
  a1_133 = _131 - _122;
  a2_134 = _118 + _126;
  _135 = _118 - _126;
  _136 = _135 * 2896;
  a3_137 = _136 >> 11;
  a4_138 = _120 + _124;
  a5_139 = _124 - _120;
  a6_140 = _117 + _128;
  a7_141 = _117 - _128;
  b0_142 = a4_138 + a6_140;
  _143 = a5_139 + a7_141;
  _144 = _143 * 3784;
  b1_145 = _144 >> 11;
  _146 = a5_139 * -5352;
  _147 = _146 >> 11;
  _148 = _147 - b0_142;
  b2_149 = b1_145 + _148;
  _150 = a6_140 - a4_138;
  _151 = _150 * 2896;
  _152 = _151 >> 11;
  b3_153 = _152 - b2_149;
  _154 = a7_141 * 2217;
  _155 = _154 >> 11;
  _156 = b3_153 + _155;
  b4_157 = _156 - b1_145;
  _158 = a0_132 + a2_134;
  _159 = b0_142 + _158;
  MEM[(int *)&temp][i_199] = _159;
  _160 = a1_133 + a3_137;
  _161 = _160 - a2_134;
  _162 = b2_149 + _161;
  MEM[(int *)_10 + 32B] = _162;
  _163 = a1_133 - a3_137;
  _164 = a2_134 + _163;
  _165 = b3_153 + _164;
  MEM[(int *)_10 + 64B] = _165;
  _166 = a0_132 - a2_134;
  _167 = _166 - b4_157;
  MEM[(int *)_10 + 96B] = _167;
  _168 = b4_157 + _166;
  MEM[(int *)_10 + 128B] = _168;
  _169 = _164 - b3_153;
  MEM[(int *)_10 + 160B] = _169;
  _170 = _161 - b2_149;
  MEM[(int *)_10 + 192B] = _170;
  _171 = _158 - b0_142;
  MEM[(int *)_10 + 224B] = _171;

  <bb 6>:
  i_12 = i_199 + 1;
  ivtmp_623 = ivtmp_624 - 1;
  if (ivtmp_623 != 0)
    goto <bb 7>;
  else
    goto <bb 8>;

  <bb 7>:
  goto <bb 3>;

into

  <bb 4>:
  # i_199 = PHI <i_12(5), 0(3)>
  # ivtmp_624 = PHI <ivtmp_623(5), 8(3)>
  _6 = (long unsigned int) i_199;
  _7 = _6 * 4;
  _9 = block_8(D) + _7;
  _10 = &temp + _7;
  _117 = MEM[(const int32_t *)_9 + 32B];
  _118 = MEM[(const int32_t *)_9 + 64B];
  _119 = _117 | _118;
  _120 = MEM[(const int32_t *)_9 + 96B];
  _121 = _119 | _120;
  _122 = MEM[(const int32_t *)_9 + 128B];
  _123 = _121 | _122;
  _124 = MEM[(const int32_t *)_9 + 160B];
  _125 = _123 | _124;
  _126 = MEM[(const int32_t *)_9 + 192B];
  _127 = _125 | _126;
  _128 = MEM[(const int32_t *)_9 + 224B];
  _129 = _127 | _128;
  _130 = MEM[(const int32_t *)_9];
  _ifc__525 = MEM[(int *)_10 + 224B];
  _ifc__524 = _130;
  _ifc__523 = _129 == 0 ? _ifc__524 : _ifc__525;
  MEM[(int *)_10 + 224B] = _ifc__523;
  _ifc__522 = MEM[(int *)_10 + 192B];
  _ifc__521 = _130;
  _ifc__520 = _129 == 0 ? _ifc__521 : _ifc__522;
  MEM[(int *)_10 + 192B] = _ifc__520;
  _ifc__519 = MEM[(int *)_10 + 160B];
  _ifc__518 = _130;
  _ifc__517 = _129 == 0 ? _ifc__518 : _ifc__519;
  MEM[(int *)_10 + 160B] = _ifc__517;
  _ifc__516 = MEM[(int *)_10 + 128B];
  _ifc__515 = _130;
  _ifc__514 = _129 == 0 ? _ifc__515 : _ifc__516;
  MEM[(int *)_10 + 128B] = _ifc__514;
  _ifc__513 = MEM[(int *)_10 + 96B];
  _ifc__512 = _130;
  _ifc__511 = _129 == 0 ? _ifc__512 : _ifc__513;
  MEM[(int *)_10 + 96B] = _ifc__511;
  _ifc__510 = MEM[(int *)_10 + 64B];
  _ifc__509 = _130;
  _ifc__508 = _129 == 0 ? _ifc__509 : _ifc__510;
  MEM[(int *)_10 + 64B] = _ifc__508;
  _ifc__507 = MEM[(int *)_10 + 32B];
  _ifc__506 = _130;
  _ifc__505 = _129 == 0 ? _ifc__506 : _ifc__507;
  MEM[(int *)_10 + 32B] = _ifc__505;
  _ifc__504 = MEM[(int *)&temp][i_199];
  _ifc__503 = _130;
  _ifc__502 = _129 == 0 ? _ifc__503 : _ifc__504;
  MEM[(int *)&temp][i_199] = _ifc__502;
  _131 = MEM[(const int32_t *)_9];
  a0_132 = _122 + _131;
  a1_133 = _131 - _122;
  a2_134 = _118 + _126;
  _135 = _118 - _126;
  _136 = _135 * 2896;
  a3_137 = _136 >> 11;
  a4_138 = _120 + _124;
  a5_139 = _124 - _120;
  a6_140 = _117 + _128;
  a7_141 = _117 - _128;
  b0_142 = a4_138 + a6_140;
  _143 = a5_139 + a7_141;
  _144 = _143 * 3784;
  b1_145 = _144 >> 11;
  _146 = a5_139 * -5352;
  _147 = _146 >> 11;
  _148 = _147 - b0_142;
  b2_149 = b1_145 + _148;
  _150 = a6_140 - a4_138;
  _151 = _150 * 2896;
  _152 = _151 >> 11;
  b3_153 = _152 - b2_149;
  _154 = a7_141 * 2217;
  _155 = _154 >> 11;
  _156 = b3_153 + _155;
  b4_157 = _156 - b1_145;
  _158 = a0_132 + a2_134;
  _159 = b0_142 + _158;
  _ifc__501 = MEM[(int *)&temp][i_199];
  _ifc__500 = _159;
  _ifc__499 = _129 == 0 ? _ifc__501 : _ifc__500;
  MEM[(int *)&temp][i_199] = _ifc__499;
  _160 = a1_133 + a3_137;
  _161 = _160 - a2_134;
  _162 = b2_149 + _161;
  _ifc__498 = MEM[(int *)_10 + 32B];
  _ifc__497 = _162;
  _ifc__496 = _129 == 0 ? _ifc__498 : _ifc__497;
  MEM[(int *)_10 + 32B] = _ifc__496;
  _163 = a1_133 - a3_137;
  _164 = a2_134 + _163;
  _165 = b3_153 + _164;
  _ifc__495 = MEM[(int *)_10 + 64B];
  _ifc__494 = _165;
  _ifc__493 = _129 == 0 ? _ifc__495 : _ifc__494;
  MEM[(int *)_10 + 64B] = _ifc__493;
  _166 = a0_132 - a2_134;
  _167 = _166 - b4_157;
  _ifc__492 = MEM[(int *)_10 + 96B];
  _ifc__487 = _167;
  _ifc__486 = _129 == 0 ? _ifc__492 : _ifc__487;
  MEM[(int *)_10 + 96B] = _ifc__486;
  _168 = b4_157 + _166;
  _ifc__485 = MEM[(int *)_10 + 128B];
  _ifc__484 = _168;
  _ifc__483 = _129 == 0 ? _ifc__485 : _ifc__484;
  MEM[(int *)_10 + 128B] = _ifc__483;
  _169 = _164 - b3_153;
  _ifc__482 = MEM[(int *)_10 + 160B];
  _ifc__481 = _169;
  _ifc__480 = _129 == 0 ? _ifc__482 : _ifc__481;
  MEM[(int *)_10 + 160B] = _ifc__480;
  _170 = _161 - b2_149;
  _ifc__479 = MEM[(int *)_10 + 192B];
  _ifc__478 = _170;
  _ifc__477 = _129 == 0 ? _ifc__479 : _ifc__478;
  MEM[(int *)_10 + 192B] = _ifc__477;
  _171 = _158 - b0_142;
  _ifc__476 = MEM[(int *)_10 + 224B];
  _ifc__475 = _171;
  _ifc__474 = _129 == 0 ? _ifc__476 : _ifc__475;
  MEM[(int *)_10 + 224B] = _ifc__474;
  i_12 = i_199 + 1;
  ivtmp_623 = ivtmp_624 - 1;
  if (ivtmp_623 != 0)
    goto <bb 5>;
  else
    goto <bb 12>;

  <bb 5>:
  goto <bb 4>;

note how this transforms

  if (pred)
   temp[i] = ...;
  else
   temp[i] = ...;

into

  tem = temp[i];
  temp[i] = pred ? ... : tem;
  tem2 = temp[i];
  temp[i] = !pred ? ... : tem;

and thus reads from uninitialized temp[].  Part of the GIMPLE IL is

  _ifc__525 = MEM[(int *)_10 + 224B];
  _ifc__524 = _130;
  _ifc__523 = _129 == 0 ? _ifc__524 : _ifc__525;
  MEM[(int *)_10 + 224B] = _ifc__523;
...
  _ifc__476 = MEM[(int *)_10 + 224B];
  _ifc__475 = _171;
  _ifc__474 = _129 == 0 ? _ifc__476 : _ifc__475;
  MEM[(int *)_10 + 224B] = _ifc__474;

Confirmed also as missed optimization, if-conversion should do a better
job for this.  OTOH we miss a general scalar transform that would sink
stores to common locations to the merger block, then if-conversion would
have a simpler job.

Reply via email to