[Bug c++/84436] New: Missed optimization with switch on enum constants returning the same value
mferoldif at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sun Feb 18 13:25:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84436
Bug ID: 84436
Summary: Missed optimization with switch on enum constants
returning the same value
Product: gcc
Version: 7.3.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mferoldif at gmail dot com
Target Milestone: ---
The following snippet:
enum class E
{
A, B, C,
};
int foo(E e)
{
switch (e)
{
case E::A: return 0;
case E::B: return 1;
case E::C: return 2;
}
}
Produces the following ineffective code:
foo(E):
cmp edi, 1
mov eax, 1
je .L1
cmp edi, 2
mov eax, 2
je .L1
xor eax, eax
.L1:
rep ret
There is no reason why it should not produce a single `mov eax, edi`
and ret instruction.
More information about the Gcc-bugs
mailing list