User account creation filtered due to spam.

Bug 21223 - Output register variable is reloaded into the wrong register for asm
Summary: Output register variable is reloaded into the wrong register for asm
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-04-25 20:49 UTC by Daniel Jacobowitz
Modified: 2006-01-26 05:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.3.3 4.1.0 2.95.3
Last reconfirmed: 2006-01-26 05:37:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Jacobowitz 2005-04-25 20:49:25 UTC
Compile this test with an ARM-targeted compiler.  Using -O2, it works out OK;
but for -O0 or -O1 it doesn't.  I originally encountered the bug in -O2 compiled
code, but a more complex testcase is probably necessary for that.

int bar(int *mem)
{
  return ({ register int a_oldval asm ("r0");
            register int a_tmp asm ("r3");
            int a_oldval2 = 3;
            __asm__ __volatile__ ("# Should be r0 - %0\n\t"
                                  "# Should be r3 - %1"
                                  : "=&r" (a_oldval), "=&r" (a_tmp)
                                  : "r" (a_oldval2));
            a_tmp; });
}

Everything is OK up until reload.  Then this happens:

Spilling for insn 19.
Using reg 2 for reload 0
Spilling for insn 19.
Using reg 2 for reload 0

Reloads for insn # 19
Reload 0: reload_out (SI) = (reg/v:SI 3 r3 [ a_tmp ])
        GENERAL_REGS, RELOAD_OTHER (opnum = 1)
        reload_out_reg: (reg/v:SI 3 r3 [ a_tmp ])
        reload_reg_rtx: (reg:SI 2 r2)

and the set of a_tmp is replaced by a set of r2.  I can't figure out why
the reload was created.
Comment 1 Andrew Pinski 2005-04-25 20:54:01 UTC
Confirmed, also on powerpc-darwin. Weird.
Comment 2 Daniel Jacobowitz 2005-04-25 21:07:54 UTC
The reload was created because the earlyclobber operand conflicts with
a_oldval2, which is placed in r3 by local-alloc.  I think I see why...
Comment 3 Andrew Pinski 2005-04-25 21:09:49 UTC
And here is an x86 testcase:
int bar(int *mem)
{
  return ({ register int a_oldval asm ("eax");
            register int a_tmp asm ("ebx");
            int a_oldval2 = 3;
            __asm__ __volatile__ ("# Should be eax - %0\n\t"
                                  "# Should be ebx - %1\n\t"
                                  "# unknown - %2"
                                  : "=&r" (a_oldval), "=&r" (a_tmp)
                                  : "r" (a_oldval2));
            a_tmp; });
}

Which shows this fails at -O2 and above too.
Comment 4 Daniel Jacobowitz 2005-04-25 21:12:59 UTC
The problem is in reg_is_set or its caller.

Because the output is an earlyclobber operand, it needs to be marked as born
before the insn, to conflict with its inputs.  I do not see an obvious way to
get from note_stores to the recog alternative.

I reproduced this bug in 3.4.3 (csl-arm-branch) also.