https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97417
Bug ID: 97417
Summary: RISC-V Unnecessary andi instruction when loading
volatile bool
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
Assignee: unassigned at gcc dot gnu.org
Reporter: kjetilos at gmail dot com
Target Milestone: ---
When loading a volatile bool value I see that the compiler adds unnecessary
andi instruction. Here is reproducer:
#include <stdbool.h>
extern volatile bool active;
int foo(void)
{
if (!active) {
return 42;
} else {
return -42;
}
}
And the code generated looks like this:
foo:
lui a5,%hi(active)
lbu a5,%lo(active)(a5)
li a0,42
andi a5,a5,0xff
beq a5,zero,.L1
li a0,-42
.L1:
ret
The andi instruction seems to be unnecessary since lbu is zero extending the
byte.
ref. https://github.com/riscv/riscv-gnu-toolchain/issues/737