public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/28126]  New: gcc moves an expensive instruction outside of a conditional
@ 2006-06-21 16:04 anemo at mba dot ocn dot ne dot jp
  2006-06-21 16:36 ` [Bug target/28126] " daney at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: anemo at mba dot ocn dot ne dot jp @ 2006-06-21 16:04 UTC (permalink / raw)
  To: gcc-bugs

The RDHWR instruction is used to support TLS on Linux/MIPS.  For now
it is always emulated by kernel (on Reserved Instruction exception
handler), the instruction will be quite expensive.

If I compile this code with gcc 4.1.1 (-O2),

extern __thread int x;
int foo(int arg)
{
        if (arg)
                return x;
        return 0;
}

I got this output.

foo:
        .frame  $sp,0,$31               # vars= 0, regs= 0/0, args= 0, gp= 0
        .mask   0x00000000,0
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro

        lw      $2,%gottprel(x)($28)
        .set    push
        .set    mips32r2        
        rdhwr   $3,$29
        .set    pop
        addu    $2,$2,$3
        beq     $4,$0,$L4
        move    $3,$0

        lw      $3,0($2)
$L4:
        j       $31
        move    $2,$3

The RDHWR is executed _before_ evaluating the "arg" value.  For arg ==
0 case, the RDHWR has no point but just a overhead.  Without -O2, the
RDHWR is executed _after_ the evaluation, so gcc's optimizer reorder
the RDHWR instruction.

If I used -O instead of -O2, I got:

foo:
        .frame  $sp,0,$31               # vars= 0, regs= 0/0, args= 0, gp= 0
        .mask   0x00000000,0
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro

        bne     $4,$0,$L2
        .set    push
        .set    mips32r2        
        rdhwr   $3,$29
        .set    pop

        j       $31
        move    $2,$0

$L2:
        lw      $2,%gottprel(x)($28)
        nop
        addu    $2,$2,$3
        lw      $2,0($2)
        j       $31
        nop

This is not desired too since rdhwr on delay slot is executed unconditionally.


-- 
           Summary: gcc moves an expensive instruction outside of a
                    conditional
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anemo at mba dot ocn dot ne dot jp
GCC target triplet: mips*-*-linux


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


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

end of thread, other threads:[~2008-09-08 19:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-21 16:04 [Bug c/28126] New: gcc moves an expensive instruction outside of a conditional anemo at mba dot ocn dot ne dot jp
2006-06-21 16:36 ` [Bug target/28126] " daney at gcc dot gnu dot org
2006-06-22  4:46 ` kkojima at gcc dot gnu dot org
2006-07-06 16:20 ` anemo at mba dot ocn dot ne dot jp
2006-07-12 16:08 ` drow at gcc dot gnu dot org
2006-07-13 14:42 ` anemo at mba dot ocn dot ne dot jp
2006-07-13 14:58 ` anemo at mba dot ocn dot ne dot jp
2006-07-21 16:34 ` anemo at mba dot ocn dot ne dot jp
2006-07-30 10:56 ` rsandifo at gcc dot gnu dot org
2006-08-03 21:07 ` rsandifo at gcc dot gnu dot org
2006-08-05 15:48 ` anemo at mba dot ocn dot ne dot jp
2008-09-07 17:33 ` daney at gcc dot gnu dot org
2008-09-08 19:49 ` rdsandiford at googlemail 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).