https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118687
Bug ID: 118687 Summary: RISC-V extensions for inline asm code (vs. llvm) Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: vineetg at gcc dot gnu.org CC: charlie at rivosinc dot com, jeffreyalaw at gmail dot com Target Milestone: --- I think I know the resolution but opening this bug for discussion anyways. Charlie reported some kernel code has an inline asm whcih uses a LI + large const, which can possibly be synthesized optimally with bitmanip extension. long ret_from_fork() { long ret; asm ("li %[ret],%[c1]\n" : [ret] "=r" (ret) : [c1] "i" (0x0123456789abcdefull)); return ret; } However gcc is ignoring the bitmanip flag and generating the "invalid asm" ret_from_fork: li a0,81985529216486895 ret Ultimately the assembler synthesizes it using basic codegen (it is not expected to re-implement the compiler anyways). lui a0,0x92 addiw a0,a0,-1493 slli a0,a0,0xc addi a0,a0,965 slli a0,a0,0xd addi a0,a0,-1347 slli a0,a0,0xc addi a0,a0,-529 ret The question is - is this as designed or a bug. My guy says inline asm is meant to keep the compiler out of the way so gcc is doing the right thing. But then RISC-V llvm seems to be generating the optimal bitmanip enabled sequence for the same test. https://godbolt.org/z/W3G4e6qnv