[clang] [Clang][AArch64] Use __clang_arm_builtin_alias for overloaded svreinterpret's (PR #92427)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 20 01:58:38 PDT 2024


rsandifo-arm wrote:

> clang specifically diagnoses always_inline functions. So for example, say you want to write something like:
> 
> ```
> #include <arm_sve.h>
> __attribute__((always_inline, target("+sve")))
> static inline void f(void* p) __arm_streaming_compatible {
>   *(svuint32_t*)p = svmul_m(svptrue_b32(), *(svuint32_t*)p, *(svuint32_t*)p);
> }
> //////////
> void g(void* p) __arm_streaming { f(p); }
> ```
> 
> Conceptually, this should be fine, but currently it's an error. (You can sort of approximate it with an `#ifdef __ARM_FEATURE_SVE`, but that's pretty ugly.)

Yeah.  I think in GCC, the reason for the equivalent behaviour is that (a) the compiler assumes (without checking) that the contents really do require the given target and (b) the compiler doesn't support changes to the ISA within a function.  So the error is that the target mismatch caused inlining to fail, rather than that the mismatch occurred at all.

> But regardless of the diagnostics, if the user specifies "+sve" on a target that doesn't actually have SVE, we could miscompile; for example, if you call a versioned function, clang uses the features specified in the caller.

That's a good point.  I suppose it comes down to two fundamentally different use cases:

1. A function that can be called in either PSTATE.SM mode and “just work”.  This is what `__arm_streaming_compatible` is currently supposed to provide.  That is, what the function can do is determined by where the function can be called (which is anywhere).
2. A function that cannot be called with PSTATE.SM==0 on targets that have SME but not SVE.  That is, where the function can be called is determined by what the function can do.

Perhaps (2) could be called “streaming SVE functions”.  If the compiler is supposed to enforce the constraints, then the set of assumed streaming SVE features would need to be a property of the function type.

https://github.com/llvm/llvm-project/pull/92427


More information about the cfe-commits mailing list