-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][LoongArch] LSX/LASX headers do not work with -fno-lax-vector-conversions
#110834
Comments
Sketch: https://godbolt.org/z/s94GWb3fs Sketch code// compile with: -O1 -mlsx -fno-lax-vector-conversions
// for Clang, add --target=loongarch64 if not natively experimenting
#ifdef __clang__
// #include <lsxintrin.h>
typedef signed char v16i8 __attribute__((vector_size(16), aligned(16)));
typedef long long __m128i __attribute__((__vector_size__(16), __may_alias__));
// clang distinguishes between "signed char" and "char"
// __builtin_lsx_vsll_b is defined with the following:
//
// TARGET_BUILTIN(__builtin_lsx_vsll_b, "V16cV16cV16c", "nc", "lsx")
//
// so it doesn't accept "signed char" vectors
// (each "V16c" would have to become "V16Sc" for "signed char")
//
// kludge without modifying Clang: provide a v16i8 defined with bare "char"
typedef char v16c8 __attribute__((vector_size(16), aligned(16)));
#else
#include <lsxintrin.h>
typedef v16i8 v16c8;
#endif
__m128i __lsx_vsll_b_xxx(__m128i _1, __m128i _2) {
// return (__m128i)__builtin_lsx_vsll_b((v16i8)_1, (v16i8)_2);
return (__m128i)__builtin_lsx_vsll_b((v16c8)_1, (v16c8)_2);
} We probably have to provide a bare |
CC-ing people for better visibility, this is best handled ASAP because toolchain changes can take a long time to propagate to distros: cc @ChenghuaXu @chenglulu326 @SixWeining @heiher @xry111 (toolchain) |
AFAIK removing "signed" is not an option because it'll cause stupid things if someone uses |
Thus the correct thing to do is fixing clang builtin to accept a |
…rsions=none` Change all `V16c` and `V32c` to `V16Sc` and `V32Sc`, and fix some other random inconsistencies between the builtins and the intrinsic headers. Add tests two ensure the intrinsic headers work with `-flax-vector-conversions=none`. Fixes llvm#110834.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
I completely agree with your point. |
Previously I worried about compatibility of signatures of the builtins, but @xry111 told me yesterday that the public API surface is the intrinsic header and not the builtins. And with the immediate errors on the inclusion of the header, there's no previously-working code that would be regressed by the signature change either. So I would also agree that amending the builtins' signatures is the best way forward. |
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
signed char
vectors instead of char
vectors for LSX and LASX builtins
#114510
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
…s for LSX and LASX builtins (#114510) `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def Depends on #114509. Part of #110834 fix.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
… builtins `unsigned char` vectors The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834.
@SixWeining @xry111 -- Thanks for the fix and quick review & merge; I think it may also be appropriate to backport this patchset to LLVM 19.x because this would allow downstream to drop their kludges 6 months earlier. (We have to act quick though, LLVM 19.1.4 is slated for Nov 12th i.e. a week from now. I cannot help this time due to very tight schedule though.) |
Yes, I think so. |
/pull-request #114958 |
…b builtins `signed char` vectors (llvm#114512) The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. Depends on llvm#114511. Part of llvm#110834 fix.
… builti ns `unsigned char` vectors (llvm#114513) The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834. Depends on llvm#114512.
(cherry picked from commit 96d2196)
…s for LSX and LASX builtins (llvm#114510) `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def Depends on llvm#114509. Part of llvm#110834 fix. (cherry picked from commit b885054)
…b builtins `signed char` vector (llvm#114511) These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. Depends on llvm#114510. Part of llvm#110834 fix. (cherry picked from commit 92daad2)
…b builtins `signed char` vectors (llvm#114512) The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. Depends on llvm#114511. Part of llvm#110834 fix. (cherry picked from commit 4006b28)
… builti ns `unsigned char` vectors (llvm#114513) The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834. Depends on llvm#114512. (cherry picked from commit 4f740f9)
(cherry picked from commit 96d2196)
…s for LSX and LASX builtins (llvm#114510) `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def Depends on llvm#114509. Part of llvm#110834 fix. (cherry picked from commit b885054)
…b builtins `signed char` vector (llvm#114511) These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. Depends on llvm#114510. Part of llvm#110834 fix. (cherry picked from commit 92daad2)
…b builtins `signed char` vectors (llvm#114512) The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. Depends on llvm#114511. Part of llvm#110834 fix. (cherry picked from commit 4006b28)
… builti ns `unsigned char` vectors (llvm#114513) The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834. Depends on llvm#114512. (cherry picked from commit 4f740f9)
(cherry picked from commit 96d2196)
…s for LSX and LASX builtins (llvm#114510) `-flax-vector-conversions=none` does not allow an implicit conversion from `signed char` vector to `char` vector, and we cannot remove `signed` from `v16i8` or `v32i8` because doing so will break our expectation with `-fno-signed-char`. So to make lsxintrin.h and lasxintrin.h work fine with `-flax-vector-conversions=none`, we must use `signed char` instead of `char`. The change is just done via sed 's/V16c/V16Sc/g' -i BuiltinsLoongArchLSX.def sed 's/V32c/V32Sc/g' -i BuiltinsLoongArchLASX.def Depends on llvm#114509. Part of llvm#110834 fix. (cherry picked from commit b885054)
…b builtins `signed char` vector (llvm#114511) These builtins operate on int8 vectors, not int16 vectors. So the old definition does not make any sense. Depends on llvm#114510. Part of llvm#110834 fix. (cherry picked from commit 92daad2)
…b builtins `signed char` vectors (llvm#114512) The lsxintrin.h and and lasxintrin.h headers uses `signed char` vectors instead of `unsigned char` vectors. GCC also uses `signed char` for them, so align their definition with the headers and GCC. Depends on llvm#114511. Part of llvm#110834 fix. (cherry picked from commit 4006b28)
… builti ns `unsigned char` vectors (llvm#114513) The lsxintrin.h and and lasxintrin.h headers uses `unsigned char` vectors instead of `signed char` vectors. GCC also uses `unsigned char` for them, so align their definition with the headers and GCC. Fixes llvm#110834. Depends on llvm#114512. (cherry picked from commit 4f740f9)
The current Clang LSX/LASX intrinsics header files make heavy use of
implicit vector conversionsvector bitcasts, that is not accepted by Clang 18+ (Clang 17 does not support Loongson SIMD) with-fno-lax-vector-conversions
. Example:It complicates distribution packaging for certain software, because
-flax-vector-conversions
here and there, for example Skia.So it may be best to just fix the headers to work with strict vector conversion checks, to stop the proliferation of lax coding practice.
The text was updated successfully, but these errors were encountered: