public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111576] New: gcc generates conditional branch for bitwise "&"
@ 2023-09-24 21:50 eggert at cs dot ucla.edu
  2023-09-24 21:51 ` [Bug tree-optimization/111576] " eggert at cs dot ucla.edu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eggert at cs dot ucla.edu @ 2023-09-24 21:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111576
           Summary: gcc generates conditional branch for bitwise "&"
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 55983
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55983&action=edit
source code for branch-free test for "." or ".."

Although this is low prioriy for me, I thought I'd mention it in case it would
help GCC optimize better for others.

I looked into implementing a test for "." or ".." that was branch free. In
other words, implement "strcmp (p, ".") == 0 || strcmp (p, "..") == 0" without
using conditional branches. I came up with an expression that should do this,
but GCC translates a bitwise "&" into code that involves conditional branches.
Normally I would think conditional branches would be better avoided for bitwise
"&".

To see the situation, compile the attached program t.c with 'gcc -O2 -S t.c'
using gcc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1). It generates the attached
assembly language output t.s. The code generated for 'f' contains two
conditional branches, even though the source uses '&'. Furthermore, the
generated code evaluates the more complicated side of the '&' first, to see
whether it should evaluate the easy part, and this is not likely to be faster
than just evaluating the whole thing.

The code generated for the logically equivalent function 'g' is branch free,
but g's source code is trickier as it substitutes "~+!!" for plain "!". (The
"+" is present to work around GCC bug 111715.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-25  1:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-24 21:50 [Bug tree-optimization/111576] New: gcc generates conditional branch for bitwise "&" eggert at cs dot ucla.edu
2023-09-24 21:51 ` [Bug tree-optimization/111576] " eggert at cs dot ucla.edu
2023-09-24 22:04 ` [Bug middle-end/111576] " pinskia at gcc dot gnu.org
2023-09-24 22:05 ` pinskia at gcc dot gnu.org
2023-09-24 22:09 ` pinskia at gcc dot gnu.org
2023-09-25  1:35 ` eggert at cs dot ucla.edu

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).