public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "benjamin.meier70 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/106822] "Boolean-or" optimization opportunity not consistently used
Date: Sat, 03 Sep 2022 23:55:41 +0000	[thread overview]
Message-ID: <bug-106822-4-Z3gOe1M99Z@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106822-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106822

--- Comment #3 from Benjamin B. Meier <benjamin.meier70 at gmail dot com> ---
> The reason for the difference is because in the case where there is an int in the structure, the alignment is 4 bytes so a 2 or 4 byte read for a and b will not cause an fault while in the first case where there is no int, the alignment is 1 and might cause a fault. Gcc is conservative here on doing the optimization.

Okay, got it. The alignment actually makes a difference here. Thanks, for the
explanation.

> Also || is a short cutting or in c so I don't think this optimization can be done for the original case in a well defined way.

I see that as well, however reading the right hand side expression of the
||-operator has in this case no observable side-effect. Plus if we know that
s->a can be read, we know as well that s cannot be a NULL pointer. Given that,
I would assume the optimization should be valid (and applied).

Another supporting argument for ignoring the short cutting behavior is the
version of "MyStruct" with "int x;": In this case the compiler also always
reads both operands (and therefore ignores the short cut).

So if the compiler uses a nice optimization without jumps if it knows the
alignment is at least 2 bytes, it probably could also use an optimization for
the case that the alignment is only 1 byte. A possible optimization would then
look like the code of f2.

Finally, it's nothing really important, but I still do not yet completely see
why optimizing the jump away in f is an issue:)

  parent reply	other threads:[~2022-09-03 23:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-03 22:48 [Bug c/106822] New: " benjamin.meier70 at gmail dot com
2022-09-03 22:55 ` [Bug c/106822] " benjamin.meier70 at gmail dot com
2022-09-03 23:08 ` [Bug tree-optimization/106822] " pinskia at gcc dot gnu.org
2022-09-03 23:55 ` benjamin.meier70 at gmail dot com [this message]
2022-09-05 10:19 ` rguenth at gcc dot gnu.org
2022-09-05 14:27 ` benjamin.meier70 at gmail dot com

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=bug-106822-4-Z3gOe1M99Z@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).