-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
Description
Example:
int loop_body(int n)
{
int i, j = 0;
for (i = 0; i < n; ++i) {
for (; j < n; ++j) {
j = n + 1;
}
}
return j;
}For the initial part, Clang 11 or above generates some additional instructions, while with Clang 10, it's relatively better.
With Clang 11 or above
loop_body:
lea ecx, [rdi + 2]
xor edx, edx
test edi, edi
mov esi, 0
cmovg esi, edi
xor eax, eax(Why not xor esi, esi, which is just 2 bytes for encoding?)
And with Clang 10 or below
loop_body:
lea ecx, [rdi + 2]
xor edx, edx
xor eax, eaxI'm not exactly sure what's the point of that additional testing, GCC seem to avoid this (-Oz).
Testcase:
https://godbolt.org/z/a33nv18K1 (with Clang)
https://godbolt.org/z/3sfWKGxvq (with GCC)