public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/24609]  New: Same value duplicated in two different registers
@ 2005-11-01  5:33 ian at airs dot com
  2005-11-01  6:02 ` [Bug tree-optimization/24609] " ian at airs dot com
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: ian at airs dot com @ 2005-11-01  5:33 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2008-01-23  5:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-01  5:33 [Bug tree-optimization/24609] New: Same value duplicated in two different registers ian at airs dot com
2005-11-01  6:02 ` [Bug tree-optimization/24609] " ian at airs dot com
2005-11-01 14:54 ` pinskia at gcc dot gnu dot org
2005-11-01 16:09 ` ian at airs dot com
2005-11-01 16:17 ` pinskia at gcc dot gnu dot org
2005-11-01 18:06 ` ian at airs dot com
2005-11-01 18:46 ` ian at airs dot com
2005-11-01 18:47 ` [Bug tree-optimization/24609] [4.1 regression] " ian at airs dot com
2005-11-02  0:58 ` ian at airs dot com
2005-11-03  6:28 ` ian at airs dot com
2006-03-08 16:03 ` [Bug tree-optimization/24609] [4.1/4.2 " pinskia at gcc dot gnu dot org
2006-04-12 18:36 ` mmitchel at gcc dot gnu dot org
2006-04-27 12:36 ` rguenth at gcc dot gnu dot org
2006-05-25  2:40 ` mmitchel at gcc dot gnu dot org
2006-07-10 13:01 ` [Bug tree-optimization/24609] [4.0/4.1/4.2 " rguenth at gcc dot gnu dot org
2006-08-25  7:47 ` bonzini at gnu dot org
2006-08-25  7:48 ` bonzini at gnu dot org
2007-02-14  9:08 ` [Bug tree-optimization/24609] [4.0/4.1/4.2/4.3 " mmitchel at gcc dot gnu dot org
2007-07-04 22:11 ` pinskia at gcc dot gnu dot org
2008-01-21 17:26 ` steven at gcc dot gnu dot org
2008-01-23  6:49 ` ian at airs dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).