Created attachment 55983 [details] 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.)
Created attachment 55984 [details] Generated assembly language for the program
There is a dup of this bug.
Dup of bug 79045. *** This bug has been marked as a duplicate of bug 79045 ***
>111715 That is not a valid bug # either.
(In reply to Andrew Pinski from comment #4) > >111715 > > That is not a valid bug # either. Sorry, I meant Bug 111575.