Open
Description
Given an enum:
type Pointer = *const ();
#[derive(PartialEq, Eq)]
pub enum MyEnum {
A(Pointer),
B(Pointer),
C(Pointer),
D(Pointer),
E(Pointer),
F(Pointer),
Any,
}
The generated comparison uses jump table despite every jump target being identical:
https://godbolt.org/z/6nWW53eb5
As far as I'm aware, this jump should have been optimized away entirely, probably to something like
example::compare:
mov rax, qword ptr [rdi]
cmp rax, qword ptr [rsi]
jne .LBB0_1
cmp rax, 5
ja .LBB0_3
- lea rcx, [rip + .LJTI0_0]
- movsxd rax, dword ptr [rcx + 4*rax]
- add rax, rcx
- jmp rax
-.LBB0_5:
mov rax, qword ptr [rdi + 8]
cmp rax, qword ptr [rsi + 8]
sete al
ret
With WASM target, it's even worse, as it doesn't deduplicate the identical match arms at all:
https://godbolt.org/z/Gf16rM4MY
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to performance of generated code.Target: WASM (WebAssembly), http://webassembly.org/