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