Skip to content

Clang 11 or above generates larger code at -Oz #112421

@rilysh

Description

@rilysh

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, eax

I'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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions