问题描述:gcc编译器在O0下编译sve代码时,生成的汇编不符合预期
复现步骤 demo.c
#include <arm_sve.h>
static inline svuint64_t test(svbool_t pg, svuint64_t x, svbool_t cmp)
{
svuint64_t res = svsel_u64(cmp, x, svadd_n_u64_x(pg, x, 10ULL));
res = svsub_u64_x(pg, res, x);
return res;
}
int main(int argc, char *argv[])
{
uint64_t xInit[] = {
0, 1, 2, 3,
};
svbool_t pg = svptrue_b64();
svuint64_t x = svld1_u64(pg, xInit);
svbool_t cmp = svcmpge_n_u64(pg, x, 2ULL);
svuint64_t res = test(pg, x, cmp);
return 0;
}
编译命令:
gcc -std=c99 -O0 -march=armv8.3-a+fp+sve -o demo.exe demo.c
gcc 版本信息:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-linux-gnu/10.3.1/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,fortran,lto --enable-plugin --enable-initfini-array --disable-libgcj --without-isl --without-cloog --enable-gnu-indirect-function --build=aarch64-linux-gnu --with-stage1-ldflags=' -Wl,-z,relro,-z,now' --with-boot-ldflags=' -Wl,-z,relro,-z,now' --disable-bootstrap --with-multilib-list=lp64 --enable-bolt
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.1 (GCC)
问题现象:
生成的exe反汇编后sel指令被优化,处理逻辑错误。
0000000000400854 :
400854: 043f57bf addvl sp, sp, #-3
400858: e5811fe0 str p0, [sp, #15, mul vl]
40085c: 2518e3e0 ptrue p0.b
400860: e5e0e3e0 st1d {z0.d}, p0, [sp]
400864: e5811be1 str p1, [sp, #14, mul vl]
400868: 2518e3e0 ptrue p0.b
40086c: a5e2a3e1 ld1d {z1.d}, p0/z, [sp, #2, mul vl]
400870: 2518e3e0 ptrue p0.b
400874: a5e0a3e0 ld1d {z0.d}, p0/z, [sp]
400878: 04e00420 sub z0.d, z1.d, z0.d
40087c: 2518e3e0 ptrue p0.b
400880: e5e2e3e0 st1d {z0.d}, p0, [sp, #2, mul vl]
400884: 2518e3e0 ptrue p0.b
400888: a5e2a3e0 ld1d {z0.d}, p0/z, [sp, #2, mul vl]
40088c: 043f507f addvl sp, sp, #3
400890: d65f03c0 ret
Hi w00425151, welcome to the openEuler Community.
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here.
If you have any questions, please contact the SIG: Compiler, and any of the maintainers: @Noah , @eastb233 , @kuen , @Peilin Guo , @Haijian.Zhang , @编译小伙 , @huangxiaoquan , @笨鸟不飞就是鸡 , @cf-zhao , @周磊 , @stubCode
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
经过测试,发现commit:https://gitee.com/openeuler/gcc/commit/3a45b2fc131e4639b05f62d6064bd964d129c19b 会导致sel指令被优化。
建议该commit的提交者(@zhongyunde)分析解决。
感谢你的反馈!
相关的patch为社区的Backport, 在2020年合入,为一个比较早期的commit。当前编译器正在计划升级到新版本的gcc 12,到时很可能问题消失,建议7月底完成升级时再验证下
使用升级的新版本gcc-12 -> master分支已升级到gcc-12,经验证问题解决,sel指令不被优化,建议issue关闭(@huangxiaoquan)
经测试,该issue在GCC-12版本上消失。
但issue提出人期望能够在GCC 10.3.1修复。由于GCC 10.3.1版本仍在维护期,建议引发此issue的commit提交者(@zhongyunde)分析解决。
@编译小伙 @eastb233 @huangxiaoquan @dingguangya
登录 后才可以发表评论