public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14782] New: [3.3/3.4/hppa64-linux] gcc inlines code incorrectly at -O2
@ 2004-03-30  7:39 tausq at debian dot org
  2004-04-07  3:22 ` [Bug optimization/14782] [3.3/3.4 Regression] produces an unaligned data access " pinskia at gcc dot gnu dot org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: tausq at debian dot org @ 2004-03-30  7:39 UTC (permalink / raw)
  To: gcc-bugs

The attached code when compiled with gcc-3.3 or 3.4 at -O2 generates a "ldd -23
(%r3),%r19" sequence which is wrong. Compiling with -O1 or -O2 -fno-gcse works 
around the problem. The offending asm seems to be generated from the if-
statement in loop_unregister_transfer(). Removing the up/down calls make the 
problem go away. This test case was derived from the linux kernel, 
drivers/block/loop.c.

thanks, randolph

-------- 8< cut here 8< -------------
#define __PA_LDCW_ALIGNMENT 16
#define __ldcw_align(a) ({ \
  unsigned long __ret = (unsigned long) a;                              \
  __ret = (__ret + __PA_LDCW_ALIGNMENT - 1) & ~(__PA_LDCW_ALIGNMENT - 1); \
  (volatile unsigned int *) __ret;                                      \
})


#define __ldcw(a) ({ \
        unsigned __ret; \
        __asm__ __volatile__("ldcw 0(%1),%0" : "=r" (__ret) : "r" (a)); \
        __ret; \
})

typedef struct {
  volatile unsigned int lock[4];
} spinlock_t;

struct semaphore
{
  spinlock_t sentry;
  int count;
};

struct loop_device
{
  struct loop_func_table *lo_encryption;
  struct semaphore lo_ctl_mutex;
};

static int max_loop = 8;
static struct loop_device *loop_dev;

void __down (struct semaphore *sem);
void __up (struct semaphore *sem);

static inline void _raw_spin_lock (spinlock_t * x)
{
  volatile unsigned int *a = __ldcw_align(&x->lock[0]);

  while (__ldcw(a) == 0)
    while (*a == 0);
}

static inline void _raw_spin_unlock (spinlock_t * x)
{
  volatile unsigned int *a = __ldcw_align(&x->lock[0]);
  *a = 1;
}

inline void down (struct semaphore *sem)
{
  _raw_spin_lock (&sem->sentry);
  if (sem->count > 0) { sem->count--; }
  else { __down (sem); }
  _raw_spin_unlock (&sem->sentry);
}

inline void up (struct semaphore *sem)
{
  _raw_spin_lock (&sem->sentry);
  if (sem->count < 0) { __up (sem); }
  else { sem->count++; }
  _raw_spin_unlock (&sem->sentry);
}

int
loop_unregister_transfer (int number)
{
  struct loop_device *lo = &loop_dev[0];

  for (lo = &loop_dev[0]; lo < &loop_dev[max_loop]; lo++)
    {
      down (&lo->lo_ctl_mutex);

      if (lo->lo_encryption == 0)
        loop_release_xfer (lo);

      up (&lo->lo_ctl_mutex);
    }

  return 0;
}
-------- 8< cut here 8< -------------

-- 
           Summary: [3.3/3.4/hppa64-linux] gcc inlines code incorrectly at -
                    O2
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tausq at debian dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: hppa-linux
  GCC host triplet: hppa-linux
GCC target triplet: hppa64-linux


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


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

end of thread, other threads:[~2004-07-25 19:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30  7:39 [Bug optimization/14782] New: [3.3/3.4/hppa64-linux] gcc inlines code incorrectly at -O2 tausq at debian dot org
2004-04-07  3:22 ` [Bug optimization/14782] [3.3/3.4 Regression] produces an unaligned data access " pinskia at gcc dot gnu dot org
2004-04-07  4:19 ` tausq at debian dot org
2004-04-07  4:22 ` [Bug optimization/14782] [3.3/3.4/3.5 " pinskia at gcc dot gnu dot org
2004-06-08 19:25 ` [Bug rtl-optimization/14782] " pinskia at gcc dot gnu dot org
2004-06-11  5:36 ` tausq at debian dot org
2004-06-13 10:26 ` debian-gcc at lists dot debian dot org
2004-06-19 20:20 ` carlos at baldric dot uwo dot ca
2004-06-19 21:20 ` danglin at gcc dot gnu dot org
2004-06-20  0:08 ` danglin at gcc dot gnu dot org
2004-06-20  1:20 ` danglin at gcc dot gnu dot org
2004-06-20  6:07 ` pinskia at gcc dot gnu dot org
2004-06-20 19:23 ` debian-gcc at lists dot debian dot org
2004-06-21 21:13 ` mmitchel at gcc dot gnu dot org
2004-06-21 23:49 ` cvs-commit at gcc dot gnu dot org
2004-06-22  0:18 ` cvs-commit at gcc dot gnu dot org
2004-06-22  1:45 ` danglin at gcc dot gnu dot org
2004-07-25 18:53 ` cvs-commit at gcc dot gnu dot org
2004-07-25 19:05 ` pinskia at gcc dot gnu dot org

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).