public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jbuehler at spirentcom dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/32820]  New: optimizer malfunction when mixed with asm statements
Date: Thu, 19 Jul 2007 13:16:00 -0000	[thread overview]
Message-ID: <bug-32820-14880@http.gcc.gnu.org/bugzilla/> (raw)

The below C code is a stripped down version of some code generated
by the GHC Haskell compiler.  When it is compiled with -O, incorrect
code is generated.  The Hp variable should live in %r7 but the compiled
routine does not set %r7.  It does set it when -O is omitted.

I checked a few versions of gcc and the problem is present in at least
the following versions:

3.0.2
3.1.1
3.2.3
3.3.6
3.4.6
4.0.1
4.0.4
4.1.2

compile line:

gcc -O -o temp.s -x c temp.i -fno-strict-aliasing -S

input file:

typedef signed char StgInt8;
typedef unsigned char StgWord8;
typedef signed short StgInt16;
typedef unsigned short StgWord16;
typedef signed int StgInt32;
typedef unsigned int StgWord32;
typedef signed long long int StgInt64;
typedef unsigned long long int StgWord64;
typedef StgInt32 StgInt;
typedef StgWord32 StgWord;
typedef StgInt16 StgHalfInt;
typedef StgWord16 StgHalfWord;
typedef void* StgAddr;
typedef StgWord32 StgChar;
typedef int StgBool;
typedef float StgFloat;
typedef double StgDouble;
typedef void StgVoid;
typedef struct StgClosure_ StgClosure;
typedef StgClosure* StgClosurePtr;
typedef StgWord* StgPtr;
typedef StgWord StgOffset;
typedef struct StgTSO_* StgTSOPtr;
typedef void* StgForeignPtr;
typedef StgInt StgStackOffset;
typedef StgWord* StgStackPtr;
typedef StgWord8 StgCode;
typedef StgPtr* StgArray;
typedef char* StgByteArray;
typedef void* StgStablePtr;
typedef void *(*(*StgFunPtr)(void))(void);
typedef StgFunPtr StgFun(void);
typedef StgChar C_;
typedef StgWord W_;
typedef StgWord* P_;
typedef P_* PP_;
typedef StgInt I_;
typedef StgAddr A_;
typedef const StgWord* D_;
typedef StgFunPtr F_;
typedef StgByteArray B_;
typedef StgClosurePtr L_;
typedef StgInt64 LI_;
typedef StgWord64 LW_;
typedef struct {
  StgFunPtr stgGCEnter1;
  StgFunPtr stgGCFun;
} StgFunTable;
typedef union {
    StgWord w;
    StgAddr a;
    StgChar c;
    StgInt8 i8;
    StgInt i;
    StgPtr p;
    StgClosurePtr cl;
    StgStackOffset offset;
    StgByteArray b;
    StgTSOPtr t;
} StgUnion;
typedef struct StgRegTable_ {
  StgUnion rR1;
  StgUnion rR2;
  StgUnion rR3;
  StgUnion rR4;
  StgUnion rR5;
  StgUnion rR6;
  StgUnion rR7;
  StgUnion rR8;
  StgUnion rR9;
  StgUnion rR10;
  StgFloat rF1;
  StgFloat rF2;
  StgFloat rF3;
  StgFloat rF4;
  StgDouble rD1;
  StgDouble rD2;
  StgWord64 rL1;
  StgPtr rSp;
  StgPtr rSpLim;
  StgPtr rHp;
  StgPtr rHpLim;
  struct StgTSO_ *rCurrentTSO;
  struct bdescr_ *rNursery;
  struct bdescr_ *rCurrentNursery;
  StgWord rHpAlloc;
} StgRegTable;
typedef struct Capability_ {
    StgFunTable f;
    StgRegTable r;
} Capability;
extern W_ MainCapability[];
register P_ Sp __asm__("%" "r4");
register P_ SpLim __asm__("%" "r6");
register P_ Hp __asm__("%" "r7");
register P_ HpLim __asm__("%" "r8");

F_ stg_returnToStackTop(void) {
W_ _c2;
_c2 = (W_)((&((Capability *)MainCapability)[0].r)->rCurrentTSO);
Sp = (P_)(*((P_)(_c2+52)));
SpLim = (P_)(_c2+140);
Hp = (P_)((*((P_)((W_)((&((Capability
*)MainCapability)[0].r)->rCurrentNursery)+4))) + (-0x4U));
HpLim = (P_)((*((P_)((W_)((&((Capability
*)MainCapability)[0].r)->rCurrentNursery)))) +
(((((I_)(*((P_)((W_)((&((Capability
*)MainCapability)[0].r)->rCurrentNursery)+24))))) * 0x1000U) + (-0x1U)));
do { void *_procedure = (void *)(*((P_)((W_)Sp + (0x0 * 0x4U)))); if (((int)
_procedure) & 2) _procedure = (void *)(*((int *) (_procedure - 2))); goto
*_procedure; } while(0);
}


-- 
           Summary: optimizer malfunction when mixed with asm statements
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jbuehler at spirentcom dot com
 GCC build triplet: hppa1.0-hp-hpux11.00
  GCC host triplet: hppa1.0-hp-hpux11.00
GCC target triplet: hppa1.0-hp-hpux11.00


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


             reply	other threads:[~2007-07-19 13:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-19 13:16 jbuehler at spirentcom dot com [this message]
2007-07-25 13:09 ` [Bug middle-end/32820] " jbuehler at spirentcom dot com
2007-07-25 13:22 ` jbuehler at spirentcom dot com
2007-07-25 13:28 ` jbuehler at spirentcom dot com
2007-08-09 11:38 ` jbuehler at spirentcom dot com
2007-11-26 14:10 ` steven at gcc dot gnu dot org
2009-02-04  4:24 ` danglin at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-32820-14880@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).