https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120333
Bug ID: 120333
Summary: RISC-V: Wrong code with bitmanip extension
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Target Milestone: ---
Compiling with -O3 -march=rv64gcb causes the function foo below to be
miscompiled:
__attribute__ ((noipa)) _Bool
foo (unsigned char ch, unsigned long mask) {
return (mask << (0x3f - (ch & 0x3f))) >> 0x3f;
}
int main()
{
if (!foo (0x3f, 0x8000000000000000ul))
__builtin_abort ();
return 0;
}
The generated assembly fails to take the last shift into account:
foo:
li a5,63
andn a0,a5,a0
bext a0,a1,a0
ret