Created attachment 53339 [details] Sample code When comparing different variables to the same constants, in some cases the compiler could first combine the variables and then do a single compare. In the sample given, two variables are compared against 7. In the slow path, GCC produces the following with -O2. cmp edi, 7 setg al cmp esi, 7 setg dl or eax, edx movzx eax, al ret In the fast path, GCC produces this instead. or edi, esi xor eax, eax cmp edi, 7 setg al ret Although the expression a > 7 || b > 7 is the same as (a | b) > 7, the latter is better because it results in fewer instructions. A quick experiment shows the latter also runs quite faster. Verified with Godbolt for GCC trunk. Clang, ICC, and MSVC latest versions also miss this opportunity as per Godbolt.
(it should be possible to massage the output further to use test and setne, which ICC prefers to e.g. cmp and seta)
> Although the expression a > 7 || b > 7 is the same as (a | b) > 7, the Shoudn't the optimization be available for unsigned type only?
This can only be done for unsigned types as if either one was negative, then the check becames invalid. It is already done since GCC 11 (most likely the patch which fixed PR 95731). So this is invalid.
Sorry about that :/.