riscv-non-isa / riscv-c-api-doc

Documentation of the RISC-V C API
https://lf-riscv.atlassian.net/browse/RVG-4
Creative Commons Attribution 4.0 International
75 stars 41 forks source link

Propagation of target attributes when inlining #75

Open cmuellner opened 6 months ago

cmuellner commented 6 months ago

I just came across a difference in GCC and LLVM w.r.t. propagation of function attributes when inlining. E.g., consider the following code (built with -O3 -march=rv64gc):

#define always_inline __attribute__((always_inline))

always_inline inline int get_elem(int *p, int n)
{
    return p[n];
}

__attribute__((target("arch=+zba")))
int get_elem_fast(int *p, int n)
{
    return get_elem(p, n);
}

LLVM inlines as advised and produces:

get_elem_fast:                          # @get_elem_fast
        sh2add  a0, a1, a0
        lw      a0, 0(a0)
        ret

GCC errors out with: error: inlining failed in call to 'always_inline' 'get_elem': target specific option mismatch.

Probably there is nothing that can be done here. Still, I wanted to raise attention about that.

kito-cheng commented 6 months ago

Could you open a bugzilla entry to GCC? I think it should fix on GCC 14 branch as well, having a bugzilla entry will make sure we remember to do that :)