All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'David Malcolm' <dmalcolm@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	"linux-toolchains@vger.kernel.org"
	<linux-toolchains@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	"Jason Baron" <jbaron@akamai.com>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: RE: static_branch/jump_label vs branch merging
Date: Sat, 10 Apr 2021 12:44:55 +0000	[thread overview]
Message-ID: <0a2e658a936a4b7788b23c57ff37119b@AcuMS.aculab.com> (raw)
In-Reply-To: <3c062f70ffef2dcd48a661f7c8162fb8fbaf6869.camel@redhat.com>

From: David Malcolm
> Sent: 09 April 2021 14:49
...
> With the caveat that my knowledge of GCC's middle-end is mostly about
> implementing warnings, rather than optimization, I did some
> experimentation, with gcc trunk on x86_64 FWIW.
> 
> Given:
> 
> int __attribute__((pure)) foo(void);
> 
> int t(void)
> {
>   int a;
           = 0;
>   if (foo())
>     a++;
>   if (foo())
>     a++;
>   if (foo())
>     a++;
>   return a;
> }
> 
> At -O1 and above this is optimized to a single call to foo, returning 0
> or 3 accordingly.

Interesting horrid idea.
The code generated for the above should be:
	call	foo
	jz	label
So objtool could find the relocation entries for 'foo'
and use that information to replace the call instruction
(and maybe the jz) with a suitable alternate instruction
sequence.

Although that might end up with a game of 'whack-a-mole'
on the perverse instruction sequences the compiler
generates.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  parent reply	other threads:[~2021-04-10 12:45 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08 16:52 static_branch/jump_label vs branch merging Peter Zijlstra
2021-04-09  9:57 ` Ard Biesheuvel
2021-04-09 10:55   ` Florian Weimer
2021-04-09 11:16     ` Peter Zijlstra
2021-04-09 19:33       ` Nick Desaulniers
2021-04-09 20:11         ` Peter Zijlstra
2021-04-10 17:02         ` Segher Boessenkool
2021-04-09 11:12   ` Peter Zijlstra
2021-04-09 11:55     ` David Malcolm
2021-04-09 12:03       ` Peter Zijlstra
2021-04-09 13:01         ` Peter Zijlstra
2021-04-09 13:13           ` Peter Zijlstra
2021-04-09 13:48             ` David Malcolm
2021-04-09 18:40               ` Peter Zijlstra
2021-04-09 19:21                 ` David Malcolm
2021-04-09 20:09                   ` Peter Zijlstra
2021-04-09 21:07                     ` David Malcolm
2021-04-09 21:39                       ` Peter Zijlstra
2021-04-22 11:48                         ` Peter Zijlstra
2021-04-22 17:08                           ` Segher Boessenkool
2021-04-22 17:49                             ` Peter Zijlstra
2021-04-22 18:31                               ` Segher Boessenkool
2021-04-26 17:13                                 ` Peter Zijlstra
2021-04-10 12:44               ` David Laight [this message]
2021-04-09 13:03 ` Segher Boessenkool

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=0a2e658a936a4b7788b23c57ff37119b@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=ardb@kernel.org \
    --cc=dmalcolm@redhat.com \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.