https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97736
Bug ID: 97736
Summary: [9/10 Regression] switch codegen
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: ncm at cantrip dot org
Target Milestone: ---
In Gcc 8 and previous, the following code
bool is_vowel(char c) {
switch (c)
case'a':case'e':case'i':case'o':case'u':
return true;
return false;
}
compiled with -O2 or better, for numerous x86-64 targets,
resolves to a bitwise flag check, e.g.
lea ecx, [rdi-97]
xor eax, eax
cmp cl, 20
ja .L1
mov eax, 1
sal rax, cl
test eax, 1065233
setne al
.L1:
ret
Starting in gcc-9, this optimization is not performed
anymore at -O2 for many common targets (e.g. -march=skylake),
and we get
sub edi, 97
cmp dil, 20
ja .L2
movzx edi, dil
jmp [QWORD PTR .L4[0+rdi*8]]
.L4:
.quad .L5
.quad .L2
.quad .L2
.quad .L2
.quad .L5
.quad .L2
.quad .L2
.quad .L2
.quad .L5
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L5
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L2
.quad .L5
.L2:
mov eax, 0
ret
.L5:
mov eax, 1
ret
same as with -O0 or -O1.