From: Michael Ellerman <michael@ellerman.id.au>
To: linuxppc-dev@ozlabs.org
Subject: Re: [PATCH] powerpc: Make BUG_ON & WARN_ON play nice with compile-time optimisations
Date: Tue, 21 Mar 2006 14:45:23 +1100 [thread overview]
Message-ID: <200603211445.32454.michael@ellerman.id.au> (raw)
In-Reply-To: <20060207052220.917C668A92@ozlabs.org>
[-- Attachment #1: Type: text/plain, Size: 1698 bytes --]
On Tue, 7 Feb 2006 16:22, Michael Ellerman wrote:
> Currently if you do BUG_ON(0) you'll still get a trap instruction in your
> object, although it'll never trigger. That's ok, but a bit ugly, it'd be
> nice if the compiler could completely eliminate any trace of the BUG_ON.
>
> So update the BUG_ON & WARN_ON macros to make this possible. From the
> comment in the patch:
>
> The if statement in BUG_ON and WARN_ON gives the compiler a chance to do
> compile-time optimisation and possibly elide the entire block. The check
> for !__builtin_constant(x) has the oppposite effect, if we must do the
> test at runtime then we avoid a spurious compare and branch by ensuring
> the if condition is always true.
>
> I've confirmed it works in both cases, if the condition is false at compile
> time we get no code emitted for the BUG statement. If the condition needs
> to be evaluated at runtime we get the same code we used to, ie. only one
> test in the trap instruction.
Turns out this doesn't always do what we want, depending on what the condition
for the BUG_ON() is. Specifically the __builtin_constant_p() sometimes fails
to recognise that the condition will be constant, and so we end up with:
558: 38 00 00 00 li r0,0
55c: 0b 00 00 00 tdnei r0,0
Which is harmless but not really good enough. When gcc gets fixed
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26724) we can think about this
again.
cheers
--
Michael Ellerman
IBM OzLabs
wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)
We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next parent reply other threads:[~2006-03-21 3:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060207052220.917C668A92@ozlabs.org>
2006-03-21 3:45 ` Michael Ellerman [this message]
2006-03-21 5:51 ` [RFC/PATCH] powerpc: Make BUG_ON & WARN_ON play nice with compile-time optimisations Michael Ellerman
2006-03-22 0:16 ` Stephen Rothwell
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=200603211445.32454.michael@ellerman.id.au \
--to=michael@ellerman.id.au \
--cc=linuxppc-dev@ozlabs.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 NNTP newsgroup(s).