Skip to content

Regression on trunk: missed optimization for dead code, work as expected on clang-18 #91431

@ZY546

Description

@ZY546

Reduced code:
https://godbolt.org/z/chrT7v9vo

int m;
void func(short a, short b) {
    short f = 1;
    if(
    (f ? ((a ? b : 0) ? 1 : 0) : 0)
    -
    (f ? ((a ? b : 0) ? 1 : 0) : 0)
    ){ 
        m=1;
    }
}

Clang-trunk:

func(short, short):                              # @func(short, short)
        test    si, si
        setne   al
        sete    cl
        test    di, di
        setne   dl
        sete    sil
        and     dl, al
        or      sil, cl
        cmp     dl, sil
        jne     .LBB0_2
        mov     dword ptr [rip + m], 1
.LBB0_2:                                # %if.end
        ret

Expected code (Clang-18.1.0):

func(short, short):                              # @func(short, short)
        ret

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions