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

* [Bug tree-optimization/111576] gcc generates conditional branch for bitwise "&"
  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 ` eggert at cs dot ucla.edu
  2023-09-24 22:04 ` [Bug middle-end/111576] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: eggert at cs dot ucla.edu @ 2023-09-24 21:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Paul Eggert <eggert at cs dot ucla.edu> ---
Created attachment 55984
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55984&action=edit
Generated assembly language for the program

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

* [Bug middle-end/111576] gcc generates conditional branch for bitwise "&"
  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 ` pinskia at gcc dot gnu.org
  2023-09-24 22:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-24 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |middle-end
             Target|                            |x86_64

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is a dup of this bug.

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

* [Bug middle-end/111576] gcc generates conditional branch for bitwise "&"
  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
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-24 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 79045.

*** This bug has been marked as a duplicate of bug 79045 ***

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

* [Bug middle-end/111576] gcc generates conditional branch for bitwise "&"
  2023-09-24 21:50 [Bug tree-optimization/111576] New: gcc generates conditional branch for bitwise "&" eggert at cs dot ucla.edu
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-24 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>111715

That is not a valid bug # either.

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

* [Bug middle-end/111576] gcc generates conditional branch for bitwise "&"
  2023-09-24 21:50 [Bug tree-optimization/111576] New: gcc generates conditional branch for bitwise "&" eggert at cs dot ucla.edu
                   ` (3 preceding siblings ...)
  2023-09-24 22:09 ` pinskia at gcc dot gnu.org
@ 2023-09-25  1:35 ` eggert at cs dot ucla.edu
  4 siblings, 0 replies; 6+ messages in thread
From: eggert at cs dot ucla.edu @ 2023-09-25  1:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Paul Eggert <eggert at cs dot ucla.edu> ---
(In reply to Andrew Pinski from comment #4)
> >111715
> 
> That is not a valid bug # either.

Sorry, I meant Bug 111575.

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