[Bug tree-optimization/24609] New: Same value duplicated in two different registers

ian at airs dot com gcc-bugzilla@gcc.gnu.org
Tue Nov 1 05:33:00 GMT 2005


This test case causes the same value to be consistently stored in two different
registers.  This happens when compiling at -O2.

extern int abs (int __x);
extern int bar (short*, short, int);

struct s
{
  short int* top;
  short int* left;
  short int* diag;
};

int
foo (int *a, struct s* p, short int pv[6][16])
{
  int s = 0;
  int b;

  for (b = 0; b < 6; ++b)
    {
      int d;
      short int ps;

      if (abs (p->left[0] - p->diag[0])
          < abs (p->diag[0] - p->top[0]))
        d = 1;
      else
        d = 2;
      a[b] = d;

      ps = ((char*) p)[d - 1];

      s += bar (pv[b], ps, a[b]);
    }

  return s;
}

In the .s file generated by gcc -S -O2 foo.c, I see this:

.L12:
        movl    $1, %eax
        movl    $1, %edx
.L5:

and, later, this:
        jl      .L12
        movl    $2, %eax
        movl    $2, %edx
        jmp     .L5

These are the only ways to reach the label L5.  In other words, when we reach
.L5, %eax and %edx always have the same value.  Both registers are used one or
two times, and are then set to something else.  The duplication is useless, and
effectively wastes a register which could in principle be used to hold a more
useful value.  Setting two values in this way also makes the relatively simple
condition setting d too complicated for RTL if-conversion. 

The initial duplication appears to happen in PRE, which appears to feel that
(int) d and (unsigned int) d should be treated differently and introduces a
variable to hold (unsigned int) d.  After this duplication, nothing ever seems
to clean it up.


-- 
           Summary: Same value duplicated in two different registers
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24609



More information about the Gcc-bugs mailing list