已合并
[Backport] i386: Add avx512_avoid_vec_perm tune for c86-4g-m7 #394
[Backport] i386: Add avx512_avoid_vec_perm tune for c86-4g-m7 #394
已合并
haibaoo创建于 8月17日
haibaoo
haibaoo
8月17日

PR功能描述 / 为什么需要这个合入:
回移 GCC 上游提交 8d7b042f7c9092e168d2c745bdc3403061e41466,为 c86-4g-m7 增加 avx512_avoid_vec_perm 调优选项。

该补丁在 x86 向量化成本模型中识别 512-bit 跨 lane 向量置换。当目标处理器启用该调优选项且某个向量化方案包含 AVX512 跨 lane 置换时,提高该
方案的成本,避免向量化器选择在 c86-4g-m7 上开销较大的 AVX512 方案,并在合适的情况下选择 256-bit 向量化方案。

由于 EulerGCC GCC 12 尚不具备上游较新版本的 AVX256 vec_perm 成本统计框架,本次回移同时针对 GCC 12 的向量化成本接口进行了适配:在统计
SLP permuted-load 成本时保留 SLP node 和向量类型信息,使 x86 后端能够取得 load permutation 元数据并准确判断是否存在跨 lane 置换。

希望检视人员了解的内容:
本 PR 包含两个提交:

  1. 回移 GCC 上游 avx512_avoid_vec_perm 调优补丁,并适配 EulerGCC GCC 12 的 x86 向量成本模型和测试框架。
  2. EulerGCC GCC 12 适配补丁,在 permuted-load 成本统计过程中保留 SLP node 和向量类型信息。

上游参考提交:

https://gcc.gnu.org/cgit/gcc/commit/?id=8d7b042f7c9092e168d2c745bdc3403061e41466

该调优选项目前只为 c86-4g-m7 启用,修改范围为 x86 后端及通用向量化成本信息传递,不影响 AArch64 后端。

本 PR 新增三个 x86 测试:

  • avx512_avoid_vec_perm-1.c:验证存在跨 lane 置换时,c86-4g-m7 选择 32-byte 向量化方案。
  • avx512_avoid_vec_perm-2.c:验证 SLP 向量化过程中能够识别 AVX512 跨 lane 置换。
  • avx512_avoid_vec_perm-3.c:记录 GCC 12 loop vectorizer 对 false cross-lane permutation 的已知限制。由于当前实现不能可靠区分该场景与真
    正的跨 lane 置换,对应的 64-byte 向量化检查被标记为预期失败(XFAIL)。

Checklist:
PR格式

功能验证

  • 修改涉及后端架构

  • 补丁前:

                === GCC testsuite aggregate Summary ===
    
    • of expected passes 474373
    • of unexpected failures 34
    • of unexpected successes 18
    • of expected failures 3769
    • of unresolved testcases 15
    • of unsupported tests 16355

    补丁后:

                === GCC testsuite aggregate Summary ===
    
    • of expected passes 474378
    • of unexpected failures 34
    • of unexpected successes 18
    • of expected failures 3770
    • of unresolved testcases 15
    • of unsupported tests 16355

    结果变化来自本 PR 新增的测试,共新增 5 个 PASS 和 1 个预期 XFAIL;未出现新的 unexpected FAIL。g++ 和 gfortran 测试结果没有变化。

likedislike
Pull Request已成功合入, 合并人@openeuler-ci-bot
(感谢 haibaoo 的贡献)
haibaoohaibaoo
8月17日 创建了 pull request,commit 843c4b89
atomgit-bot
atomgit-bot
8月17日 评论:

变更摘要

本 PR 回移 GCC 上游提交 8d7b042f7c9092e168d2c745bdc3403061e41466,为 c86-4g-m7 处理器新增 avx512_avoid_vec_perm 调优选项,主要改动集中在 x86 后端:在 ix86_vector_costs 成本模型中识别 512-bit 跨 lane 向量置换,并在启用该调优选项时将相关向量化方案成本置为极大值,从而避免向量化器选择开销较大的 AVX512 方案、优先采用 256-bit 向量化。同时针对 EulerGCC GCC 12 缺少 AVX256 vec_perm 成本统计框架的情况,在 vect_model_load_cost 中保留 SLP node 与向量类型信息,使 x86 后端能取得 load permutation 元数据并准确判断跨 lane 置换。该调优仅对 c86-4g-m7 生效,不影响 AArch64。

主要改动

  • 新增 avx512_avoid_vec_perm 调优项:在 x86-tune.def 中新增 DEF_TUNE (X86_TUNE_AVX512_AVOID_VEC_PERM, ...),仅对 m_C86_4G_M7 启用;并在 i386.h 中新增 TARGET_AVX512_AVOID_VEC_PERM 宏用于访问该调优特性。
  • x86 成本模型识别跨 lane 置换:i386.cc 中为 ix86_vector_costs 新增构造函数、m_num_avx512_vec_perm[3] 计数成员和 finish_cost 覆盖,并新增 ix86_count_cross_lane_perm_p 函数;当检测到 512-bit 跨 lane vec_perm 且调优启用时,在 finish_cost 中将对应成本置为 INT_MAX。
  • 适配 GCC 12 的 SLP permuted-load 成本统计:tree-vect-stmts.cc 的 vect_model_load_cost 在记录 vec_perm 成本时,将原先传入的 0 替换为 slp_node 和 STMT_VINFO_VECTYPE (first_stmt_info),保留 SLP node 与向量类型信息以支持后续跨 lane 置换判断。
  • 新增三个 x86 测试用例:avx512_avoid_vec_perm-1.c 验证跨 lane 置换下选择 32-byte 向量化,avx512_avoid_vec_perm-2.c 验证 SLP 能识别 AVX512 跨 lane 置换,avx512_avoid_vec_perm-3.c 记录 loop vectorizer 对 false cross-lane permutation 的已知限制并标记为 XFAIL。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月17日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
openeuler-ci-botopeneuler-ci-bot成员
8月17日 将alexanderbill,li-yancheng,cf-zhao,eastb233,wangqiang95,kuenking111_admin,SegFault,wd-gitcode,chenzheng1030设为审查人
openeuler-ci-botopeneuler-ci-bot成员
8月17日 添加了label:sig/Compiler
openeuler-ci-bot
openeuler-ci-bot成员
8月17日 评论:

Welcome To openEuler Community

Hey @qq_56722097 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: Compiler ,
and any of the maintainers: @SegFault, @alexanderbill, @cf-zhao, @chenzheng1030, @eastb233, @kuenking111_admin, @li-yancheng, @wangqiang95, @wd-gitcode ,
and any of the committers: @huang-xiaoquan, @huzife, @lin-4682, @xiongzhou4 .

likedislike
openeuler-ci-botopeneuler-ci-bot成员
8月17日 添加了label:stat/needs-squash
openeuler-ci-botopeneuler-ci-bot成员
8月17日 添加了label:openeuler-cla/yes
openeuler-ci-bot
openeuler-ci-bot成员
8月17日 评论:

CLA Signature Pass

qq_56722097, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
haibaoohaibaoo
8月17日 修改了pull request 的描述
openeuler-ci-botopeneuler-ci-bot成员
8月17日 添加了label:ci_processing
openeuler-ci-bot
openeuler-ci-bot成员
8月17日 评论:

门禁正在运行, 您可以通过以下链接查看实时门禁检查结果.
若您对门禁结果含义不清晰或者遇到问题不知如何解决,可参考门禁指导手册
门禁入口及编码规范检查: multiarch/openeuler/trigger/gcc/103/console

likedislike
openeuler-ci-botopeneuler-ci-bot成员
8月18日 删除了label:ci_processing
openeuler-ci-bot
openeuler-ci-bot成员
8月18日 评论:
Check Name Build Result 详情 Build Details
check_code ❌FAILED • CodeCheck检查发现代码缺陷,请查看报告: https://www.openlibing.com/apps/entryCheckDashCode/MR_2e987c855c45478abf8fdd03451f01d0/859efe0d439c4279c789936140c2d649?projectId=300024&codeHostingPlatformFlag=gitcode #103
check_package_license ✅SUCCESS
x86_64 check_build ✅SUCCESS #111
aarch64 check_build ✅SUCCESS #103
likedislike
openeuler-ci-botopeneuler-ci-bot成员
8月18日 添加了label:ci_failed
openeuler-ci-bot
openeuler-ci-bot成员
8月18日 评论:
likedislike
zhuzhibiao1
9月2日 评论:

通过 Pass

AI 代码审阅

优点

  • 合入范围清晰,调优项仅对 c86-4g-m7 启用,新增的 x86-tune.def 条目和宏定义方式符合现有 DEF_TUNE 框架。
  • ix86_count_cross_lane_perm_p 对循环向量化中缺少 SLP load permutation 元数据的场景做保守处理,并对 false cross-lane permutation 的已知限制做了说明。
  • 新增测试覆盖了正向场景、SLP 场景和已知限制的 XFAIL 场景,测试设计合理。
  • tree-vect-stmts.cc 的改动复用了现有 record_stmt_cost 接口,仅补传 SLP node 和向量类型,未引入新的公共接口。
  • 调优计数逻辑带有 TDF_DETAILS dump,便于后续调优和问题定位。

变更文件覆盖检查

  • gcc/config/i386/i386.cc:未发现明确必须修改的问题;上下文一致,无输入冲突。
  • gcc/config/i386/i386.h:未发现明确必须修改的问题;上下文一致,无输入冲突。
  • gcc/config/i386/x86-tune.def:未发现明确必须修改的问题;上下文一致,无输入冲突。
  • gcc/testsuite/gcc.target/i386/avx512_avoid_vec_perm-1.c:未发现明确必须修改的问题;新增测试,无输入冲突。
  • gcc/testsuite/gcc.target/i386/avx512_avoid_vec_perm-2.c:未发现明确必须修改的问题;新增测试,无输入冲突。
  • gcc/testsuite/gcc.target/i386/avx512_avoid_vec_perm-3.c:未发现明确必须修改的问题;新增测试,无输入冲突。
  • gcc/tree-vect-stmts.cc:未发现明确必须修改的问题;上下文一致,无输入冲突。

需要修改的问题

未发现明确必须修改的问题。

可优化建议

建议 1:为 nunits 的 2 的幂假设增加显式断言

  • Suggestion: 在 ix86_count_cross_lane_perm_p 使用 tmp & (nunits - 1) 和 i & (nunits - 1) 之前,显式检查 nunits 是 2 的幂。
  • Reason: 当前 x86 AVX512 向量子数量都是 2 的幂,所以逻辑正确;但该函数用位与模拟取模,隐藏了对 nunits 形状的假设。增加断言可以让不变量自文档化,后续若被复用到非 power-of-two 向量类型,能尽早暴露问题。
  • Example:
    gcc_assert (nunits != 0 && (nunits & (nunits - 1)) == 0);
    unsigned half = nunits / 2;
    

建议 2:在 finish_cost 实际施加 INT_MAX 惩罚时增加 dump 信息

  • Suggestion: 当 finish_cost 因为命中 avx512_avoid_vec_perm 而把某段成本置为 INT_MAX 时,输出 TDF_DETAILS 信息。
  • Reason: 当前只在检测到跨 lane 置换时输出 dump;真正影响决策的是 finish_cost 中的惩罚。补充这一输出有助于确认具体是哪一个 cost 段被惩罚,便于后续调优和回归诊断。
  • Example:
    if (m_num_avx512_vec_perm[i] && TARGET_AVX512_AVOID_VEC_PERM)
      {
        m_costs[i] = INT_MAX;
        if (dump_file && (dump_flags & TDF_DETAILS))
          fprintf (dump_file,
                   "Rejecting 512-bit vectorization in cost slice %d\n", i);
      }
    

审阅结论

Severity: 通过

Conclusion: 建议通过

结论说明:

未发现由 diff 或现有上下文可证明的编译错误、运行崩溃、数据一致性、安全性或行为正确性问题。该 PR 的调优逻辑、宏定义、通用向量化成本信息传递以及新增测试整体合理。


Review metadata:

  • PR: #394
  • Latest commit: 1ab52ac86f5d3245a2795c3a825c5047e5f9c6f2
  • Changed lines: 192
  • Review mode: full
  • Reviewed files: 7/7
likedislike
wd-gitcode成员
9月7日 评论:

/lgtm
/approve

likedislike
openeuler-ci-botopeneuler-ci-bot成员
9月7日 添加了label:approvedlgtm
openeuler-ci-bot
openeuler-ci-bot成员
9月7日 评论:

Review Code Feedback

  • The label lgtm, approved was added to this pull request. It means that wd-gitcode reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
openeuler-ci-botopeneuler-ci-bot成员
9月7日 合入了pull request,合并节点 SHA:efae3cfaa6d9201da47bcaf67a6857c142a969fa