Bug 40762 - [4.5 Regression] CD-DCE messes up virtual SSA form
Summary: [4.5 Regression] CD-DCE messes up virtual SSA form
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P1 normal
Target Milestone: 4.5.0
Assignee: Jan Hubicka
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-07-15 06:32 UTC by John Regehr
Modified: 2009-09-07 10:24 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-07-15 10:09:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2009-07-15 06:32:52 UTC
Seen on Ubuntu Hardy.  The -O2 result seems to be wrong.  Also valgrind says this about the -O2 compilation:

==6729== Conditional jump or move depends on uninitialised value(s)
==6729==    at 0x84F22CB: solve_graph (tree-ssa-structalias.c:1570)



regehr@john-home:~/volatile/tmp174$ current-gcc -O1 small.c -o small
regehr@john-home:~/volatile/tmp174$ ./small
checksum = 0
regehr@john-home:~/volatile/tmp174$ current-gcc -O2 small.c -o small
regehr@john-home:~/volatile/tmp174$ ./small
checksum = 1
regehr@john-home:~/volatile/tmp174$ current-gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/regehr/z/tmp/gcc-r149650-install --program-prefix=r149650- --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20090714 (experimental) (GCC) 
regehr@john-home:~/volatile/tmp174$ cat small.c
#include <stdint.h>
#include <limits.h>
#include <stdio.h>

uint8_t g_4;
int64_t g_10;
uint8_t g_56;
uint8_t g_64;

static uint8_t safe_rshift_func_uint8_t_u_u(uint8_t left, unsigned int right)
{
  return ((((unsigned int)(right)) >= sizeof(uint8_t)*CHAR_BIT)
	  ? ((uint8_t)(left))
	  : (((uint8_t)(left)) >> ((unsigned int)(right))));
}

int32_t func_53 (void);
int32_t func_53 (void)
{
  if (safe_rshift_func_uint8_t_u_u (g_56, g_10))
    {
    }
  else
    for (g_10 = 0; g_10; g_10 = 1)
      {
      }
  return 1;
}

int32_t func_36 (void);
int32_t func_36 (void)
{
  uint8_t p_40;
  g_10 = 1;
  g_10 && func_53 ();
  p_40 = g_10 || g_4;
  g_64 = g_10;
  return 1;
}

int
main (void)
{
  func_36 ();
  printf ("checksum = %d\n", g_64);
  return 0;
}
Comment 1 Steven Bosscher 2009-07-15 07:46:24 UTC
Richi, this looks like it should go into your bucket of things to look at:
==6729== Conditional jump or move depends on uninitialised value(s)
==6729==    at 0x84F22CB: solve_graph (tree-ssa-structalias.c:1570)
Comment 2 Richard Biener 2009-07-15 10:09:19 UTC
Confirmed.  With -O2 -fno-inline we get in .optimized

func_36 ()
{
<bb 2>:
  g_10 = 1;
  func_53 ();
  g_64 = 1;
  return 1;

FRE does this.  I'll check.
Comment 3 Richard Biener 2009-07-15 10:17:20 UTC
We have wrong SSA form before FRE:

;; Function func_36 (func_36)

func_36 ()
{
  uint8_t g_64.8;
  int64_t g_10.5;

<bb 2>:
  # .MEM_17 = VDEF <.MEM_16(D)>
  g_10 = 1;
  # VUSE <.MEM_17>
  g_10.5_2 = g_10;
  if (g_10.5_2 != 0)
    goto <bb 3>;
  else
    goto <bb 4>;

<bb 3>:
  # .MEM_18 = VDEF <.MEM_17>
  func_53 ();

<bb 4>:
  # VUSE <.MEM_17>
  g_10.5_11 = g_10;
  g_64.8_12 = (uint8_t) g_10.5_11;
  # .MEM_19 = VDEF <.MEM_17>
  g_64 = g_64.8_12;
  return 1;

There is a PHI node missing to merge .MEM_18 and .MEM_17.

Which is caused by CD-DCE changes again.  Honza?
Comment 4 Richard Biener 2009-09-07 10:24:19 UTC
Fixed.