Skip to content

switch over select is not optimized #48896

Open
@Kojoley

Description

@Kojoley
Bugzilla Link49552
Versiontrunk
OSAll
CC@topperc,@RKSimon,@phoebewang,@rotateright

Extended Description

inline int test(char a, char b)
{
#ifndef NO_SELECT
return a < b ? -1 : a > b ? 1 : 0;
#else
if (a < b) return -1;
if (a > b) return 1;
return 0;
#endif
}

void fl();
void fe();
void fg();

void foo(char a, char b)
{
switch (test(a, b)) {
case -1: return fl();
case 0: return fe();
case 1: return fg();
}
}


; -DNO_SELECT
foo(char, char):
cmp dil, sil
jge .LBB0_1
jmp fl()
.LBB0_1:
jle .LBB0_4
jmp fg()
.LBB0_4:
jmp fe()
;
foo(char, char):
xor ecx, ecx
cmp dil, sil
setg cl
mov eax, -1
cmovge eax, ecx
cmp eax, 1
je .LBB0_5
test eax, eax
je .LBB0_4
cmp eax, -1
jne .LBB0_6
jmp fl()
.LBB0_5:
jmp fg()
.LBB0_4:
jmp fe()
.LBB0_6:
ret


https://godbolt.org/z/e9vjYK

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

      close