https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98908
Bug ID: 98908
Summary: Failure to optimize arithmetic involving struct
members into operating on the entire struct
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
struct reg {
uint8_t l;
uint8_t h;
};
reg f(reg x)
{
return {(uint8_t)(x.l & 0xFE), (uint8_t)(x.h & 0x80)};
}
This can be optimized to this:
reg f(reg x)
{
uint16_t tmp = (x.l | x.h << 8) & 0x80FE;
return {(uint8_t)tmp, (uint8_t)(tmp >> 8)};
}
. This transformation is done by LLVM, but not by GCC.