21 Star 26 Fork 89

src-openEuler / gcc

 / 详情

Bug in openEuler/gcc (10.3.1) support for ARM SVE under O0 compiler level

待办的
任务
创建于  
2023-06-12 20:51

问题描述: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

评论 (6)

vincent 创建了任务

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

openeuler-ci-bot 添加了
 
sig/Compiler
标签

经过测试,发现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)输入图片说明

当前商用的openEuler22.03 (LTS-SP2),自带的编译器还是gcc10.3.1版本,希望能将该修改回合到gcc10.3.1

经测试,该issue在GCC-12版本上消失。
但issue提出人期望能够在GCC 10.3.1修复。由于GCC 10.3.1版本仍在维护期,建议引发此issue的commit提交者(@zhongyunde)分析解决。
@编译小伙 @eastb233 @huangxiaoquan @dingguangya

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(5)
5329419 openeuler ci bot 1632792936
1
https://gitee.com/src-openeuler/gcc.git
git@gitee.com:src-openeuler/gcc.git
src-openeuler
gcc
gcc

搜索帮助