Skip to content

LLVM trunk emits ~40% larger code at -Oz compared to -O2 #111571

@dcci

Description

@dcci

Reduced from a large example:

long patatino() {
    long x = 0;
    for (int i = 0; i < 5; ++i) {
        while (x < 37) {
            if (x % 4 == 0) {
                x += 4;
            }
        }
    }
    return x;
}

-Oz

patatino():
        xorl    %eax, %eax
        xorl    %ecx, %ecx
.LBB0_1:
        cmpl    $5, %ecx
        jne     .LBB0_4
        jmp     .LBB0_2
.LBB0_5:
        testb   $3, %al
        jne     .LBB0_4
        addq    $4, %rax
.LBB0_4:
        cmpq    $36, %rax
        jle     .LBB0_5
        incl    %ecx
        jmp     .LBB0_1
.LBB0_2:
        retq

-O2

patatino():
        movl    $40, %eax
        retq

Godbolt link: https://godbolt.org/z/fzxWM693x

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