From: Richard Guenther <richard.guenther@gmail.com>
To: Hans-Peter Nilsson <hp@bitrange.com>
Cc: Mikael Pettersson <mikpe@it.uu.se>,
Michael Walle <michael@walle.cc>, Georg-Johann Lay <avr@gjlay.de>,
Richard Henderson <rth@redhat.com>,
gcc@gcc.gnu.org
Subject: Re: libgcc: strange optimization
Date: Tue, 02 Aug 2011 13:09:00 -0000 [thread overview]
Message-ID: <CAFiYyc3GRP901+giH9cDtsP0s7xUytQ03R-PNTBevr1iJY2E0g@mail.gmail.com> (raw)
In-Reply-To: <alpine.BSF.2.00.1108020837020.42404@dair.pair.com>
On Tue, Aug 2, 2011 at 2:53 PM, Hans-Peter Nilsson <hp@bitrange.com> wrote:
> On Tue, 2 Aug 2011, Richard Guenther wrote:
>> On Tue, Aug 2, 2011 at 2:06 PM, Mikael Pettersson <mikpe@it.uu.se> wrote:
>> > Michael Walle writes:
>> > >
>> > > Hi,
>> > >
>> > > > To confirm that try -fno-tree-ter.
>> > >
>> > > "lm32-gcc -O1 -fno-tree-ter -S -c test.c" generates the following working
>> > > assembly code:
>> > >
>> > > f2:
>> > > addi sp, sp, -4
>> > > sw (sp+4), ra
>> > > addi r2, r0, 10
>> > > calli __ashrsi3
>> > > addi r8, r0, 10
>> > > scall
>> > > lw ra, (sp+4)
>> > > addi sp, sp, 4
>> > > b ra
>> >
>> > -fno-tree-ter also unbreaks the ARM test case in PR48863 comment #4.
>>
>> It's of course only a workaround, not a real fix as nothing prevents
>> other optimizers from performing the re-scheduling TER does.
>>
>> I suggest to amend the documentation for local call-clobbered register
>> variables to say that the only valid sequence using them is from a
>> non-inlinable function that contains only direct initializations of the
>> register variables from constants or parameters.
>
> I'd be ok with that, FWIW; I see the problem with keeping the
> scheduling of operations in a working order (yuck) and I don't
> see how else to keep it working ...except perhaps make gcc flag
> functions with register asms as non-inlinable, maybe even flag
> down any of the dangerous re-scheduling?
But then can't people use a pure assembler stub instead? Without
inlining there isn't much benefit left from writing
void f1(int arg)
{
register int a1 asm("r8") = 10;
register int a2 asm("r1") = arg;
asm("scall" : : "r"(a1), "r"(a2));
}
instead of
f1:
mov r8, 10
mov r1, rX
scall
ret
in a .s file no? I doubt much prologue/epilogue is needed.
Or even write
void f1(int arg)
{
asm("mov r8, %0; mov r1 %1; scall;" : : "g"(a1), "g"(a2) : "r8", "r1");
}
which should be inlinable again (yes, in inlined for not optimally
register-allocated, but compared to the non-inline routine?).
Richard.
> Maybe I can do that with some hand-holding?
>
>> Or go one step further and deprecate local register variables alltogether
>> (they IMHO don't make much sense, and rather the targets should provide
>> a way to properly constrain asm inputs and outputs).
>
> They do make sense when implementing e.g. system calls, and
> they're documented to work as discussed. (I almost regret
> making that happen, though.) Fortunately such functions are
> small, and not relatively much helped by inlining (it's a
> *syscall*; much more happening beyond the call than is affected
> by inlining some parameter initialization). Sure, new targets
> are much better off by implementing that through other means,
> but preferably intrinsic functions to asms.
>
> brgds, H-P
next prev parent reply other threads:[~2011-08-02 13:09 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-01 20:30 Michael Walle
2011-08-01 20:51 ` Georg-Johann Lay
2011-08-01 21:14 ` Michael Walle
2011-08-02 6:47 ` Georg-Johann Lay
2011-08-02 6:29 ` Hans-Peter Nilsson
2011-08-01 21:30 ` Richard Henderson
2011-08-02 6:37 ` Hans-Peter Nilsson
2011-08-02 8:49 ` Mikael Pettersson
2011-08-02 9:47 ` Richard Guenther
2011-08-02 10:02 ` Georg-Johann Lay
2011-08-02 10:11 ` Richard Guenther
2011-08-02 10:55 ` Michael Walle
2011-08-02 12:06 ` Mikael Pettersson
2011-08-02 12:23 ` Richard Guenther
2011-08-02 12:36 ` Georg-Johann Lay
2011-08-02 12:54 ` Hans-Peter Nilsson
2011-08-02 13:09 ` Richard Guenther [this message]
2011-08-02 13:16 ` Hans-Peter Nilsson
2011-08-03 4:59 ` Miles Bader
2011-08-02 13:23 ` Ian Lance Taylor
2011-08-02 13:42 ` Richard Guenther
2011-08-02 14:35 ` Ian Lance Taylor
2011-08-03 9:12 ` Ulrich Weigand
2011-08-03 9:51 ` Georg-Johann Lay
2011-08-03 10:04 ` Richard Guenther
2011-08-03 13:27 ` Michael Matz
2011-08-03 14:02 ` Richard Guenther
2011-08-03 14:55 ` Georg-Johann Lay
2011-08-03 15:05 ` Richard Henderson
2011-08-04 0:20 ` Hans-Peter Nilsson
2011-08-04 7:29 ` Andreas Schwab
2011-08-04 13:04 ` Hans-Peter Nilsson
2011-08-04 9:51 ` Andrew Haley
2011-08-04 9:52 ` Richard Guenther
2011-08-04 11:11 ` Andrew Haley
2011-08-04 11:20 ` Richard Guenther
2011-08-04 14:46 ` Andrew Haley
2011-08-06 15:00 ` Paolo Bonzini
2011-08-08 8:06 ` Richard Guenther
2011-08-08 10:59 ` Paolo Bonzini
2011-08-02 16:03 ` Richard Henderson
2011-08-02 20:10 ` Richard Guenther
2011-08-02 17:21 ` Georg-Johann Lay
2011-08-09 16:55 ` Richard Earnshaw
2011-08-09 17:24 ` Ulrich Weigand
2011-08-09 19:48 ` Hans-Peter Nilsson
2011-08-10 0:40 ` Hans-Peter Nilsson
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=CAFiYyc3GRP901+giH9cDtsP0s7xUytQ03R-PNTBevr1iJY2E0g@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=avr@gjlay.de \
--cc=gcc@gcc.gnu.org \
--cc=hp@bitrange.com \
--cc=michael@walle.cc \
--cc=mikpe@it.uu.se \
--cc=rth@redhat.com \
/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).