Skip to content

fix(sve): SVE/SME 测试目标关闭严格别名——修复 TBAA 删除 svst1 导致的假 SDC - #298

Merged
wangxumarshall merged 1 commit into
mainfrom
fix/sve-strict-aliasing
Oct 26, 2026
Merged

wangxumarshall merged 1 commit into
mainfrom
fix/sve-strict-aliasing

Conversation

@wangxumarshall

@wangxumarshall wangxumarshall commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

User description

问题

CI(GCC 16.2.0)上三个用例稳定失败,报 SDC detected:

sve512_f64_chain_svd / sve512_f64_special_svd / sve512_f32_chain_svd

artifact 显示每条 lane 都是 actual=0x0000000000000000、loop-count: 0,golden 为正常非零值。

根因(已用 CI 产物反汇编确证)

这些测试的方法学是「SVE 指令算 → 写入 uint32_t/uint64_t 缓冲 → 按位与标量 golden 比较」。
svst1_f64(pg, reinterpret_cast<double *>(out), acc) 中 out 的声明类型是 uint64_t,
构成严格别名(TBAA)违规。GCC/Clang 据此判定该 double 写不与整数读别名,把 store 连同
整个 SVE 计算当死代码删除。

反汇编 CI 产物(linux-GCC-arm64-binary artifact):

函数 SVE 指令数
sve512_f64_chain_arm_run 6
sve512_f64_chain_svd_run 0
sve512_f32_chain_arm_run 6
sve512_f32_chain_svd_run 0

被删函数无任何外提调用点(其 bl 目标只有 new/delete/memset/log_message/report_fail_msg/
test_time_condition)。缓冲区只被 operator new + memset 初始化,从未被 SVE 写过 ⇒ actual 恒 0。

不是硅片 SDC,也与运行时 VL 无关。 同构最小复现在本机 GCC 12.3.1 与 Clang 17.0.6 上
均可重现(-O2 下堆缓冲保持 0),且被 -fno-strict-aliasing 修好。

修复

对 SVE/SME 专属测试库的 TU 关闭严格别名(沿用既有的 sve_sanitize_exempt 接线点):

  • tests/cpu/meson.build:新增 sve_bitpattern_exempt = ['-fno-strict-aliasing']
  • tests/cpu/arm64/meson.build、tests/cpu/sve/meson.build:6 个 SVE/SME 目标接入

影响面限于 tests_arm64_sve/_sve2/_sme 与 tests_sve_avx53/_ipsec/_crt
(532 个 TU 中 173 个带该开关),非 SVE 测试与 framework 不受影响;x86-64 零改动。

验证(如实声明边界)

  • ./scripts/build.sh 干净、零新警告
  • 开关确已进入 SVE TU 编译命令(compile_commands.json 核对)
  • 三个用例 + 全 SVE 家族在本机 VL=256 与 VL=128 两档 exit: pass
  • 回归 -e zstd19 -t 2000 -n 1 → exit: pass
  • 诚实边界:本机 GCC 12.3.1 不复现该 DCE(CI 是 GCC 16.2.0),故本机「修复后 pass」不构成
    充分证据;充分证据是上面的 CI 产物反汇编 + 双编译器最小复现。最终判据是 CI build-cpu 转绿。

衔接

该缺陷在 main 上潜伏(main:tests/cpu/arm64/sve512_f64_chain_svd.cpp:127 同样写法),
只是被 svcntb() != 64 硬门在 VL≠512 的机器上挡成 SKIP。all-VL Phase 2 去掉该门后暴露(#283/#286)。

Summary by CodeRabbit

  • 测试
    • 调整了 ARM64 SVE、SVE2 和 SME 相关测试的编译配置;不影响应用功能或用户可见行为。

PR Type

Bug fix


Description

  • Disable strict aliasing for SVE/SME tests

  • Prevent compiler from deleting svst1 stores

  • Fix false SDC reports caused by TBAA


Diagram Walkthrough

flowchart LR
  A["TBAA 优化删除了 svst1"] -- "类型双关违规" --> B["缓冲区保持零值"]
  B --> C["产生假 SDC"]
  D["引入 sve_bitpattern_exempt"] -- "-fno-strict-aliasing" --> E["保留 SVE 计算与 store"]
  E --> F["恢复正常比对"]
Loading

File Walkthrough

Relevant files
Bug fix
meson.build
定义 SVE/SME 严格别名豁免标志                                                                           

tests/cpu/meson.build

  • 定义 sve_bitpattern_exempt 为 -fno-strict-aliasing
  • 解释类型双关与 TBAA 删除 svst1 的机制
+11/-0   
meson.build
应用严格别名豁免到 arm64 测试                                                                             

tests/cpu/arm64/meson.build

  • 将 sve_bitpattern_exempt 应用到 arm64 的 SVE/SME 测试参数中
+3/-0     
meson.build
应用严格别名豁免到 sve 构建                                                                                 

tests/cpu/sve/meson.build

  • 将 sve_bitpattern_exempt 添加到 sve 相关的 meson 构建配置中
+3/-0     

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-26T10:15:58.078453Z
We couldn’t complete this review. Comment @codex review to try again.
c3c7eb6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wangxumarshall has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

GCC/Clang 的 TBAA 会把 svst1_f32/f64 写入 uint32_t/uint64_t 缓冲这一刻意
类型双关判为不与整数读别名,进而把整个 SVE 计算连同 store 当死代码删除,
缓冲区保持零值,每条 lane 报出 actual=0x0 的假 SDC。

实证:CI(GCC 16.2.0)sve512_f64_chain_svd / sve512_f64_special_svd /
sve512_f32_chain_svd 三例失败;反汇编 CI 产物,其 *_svd_run 内 SVE 指令数
为 0(同 TU 的 _arm 孪生为 6,SVE 计算被整体删除且无外提调用点)。同构最小
复现在本机 GCC 12.3.1 与 Clang 17.0.6 上均可重现,并被同一开关修好。
与 CPU 运行时 VL 无关:main 上该缺陷被 'svcntb() != 64' 硬门在 VL!=512 的
机器上挡成 SKIP,属潜伏缺陷。

影响面限定为 SVE/SME 专属测试库(tests_arm64_sve/_sve2/_sme 与
tests_sve_avx53/_ipsec/_crt),非 SVE 测试与 framework 不受影响。

Signed-off-by: sim <sim@local>
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 61b3d5a and c3c7eb6.

Files selected for processing: 3
  • tests/cpu/arm64/meson.build
  • tests/cpu/meson.build
  • tests/cpu/sve/meson.build

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

新增 sve_bitpattern_exempt 参数,值为 -fno-strict-aliasing。该参数应用于 ARM64 的 SVE、SVE2、SME 测试库,以及三个 SVE 测试库。

Changes: SVE 位模式编译参数

Layer / File(s) Summary
定义严格别名豁免参数
tests/cpu/meson.build
新增 sve_bitpattern_exempt 编译参数列表,值为 -fno-strict-aliasing。
应用到测试静态库
tests/cpu/arm64/meson.build, tests/cpu/sve/meson.build
将该参数加入 SVE、SVE2、SME 测试库,以及三个 SVE 测试库的 cpp_args。

Priority: Normal

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix

Suggested labels: Review effort 1/5

Merge Risk: Minimal · up to c3c7e

The change is limited to SVE/SME test compilation, with no established issue requiring a fix before merge.

Architecture risk: Low · up to c3c7e

The change affects 1 system.

Changed systems: tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — tests (service) was modified; 3 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in tests/cpu/arm64/meson.build: 为 SVE 静态库的编译参数新增 sve_bitpattern_exempt。
  • observed — Modified behavior in tests/cpu/arm64/meson.build: 为 SVE2 静态库的编译参数新增 sve_bitpattern_exempt。
  • observed — Modified behavior in tests/cpu/arm64/meson.build: 为 SME 静态库的编译参数新增 sve_bitpattern_exempt。
  • observed — Modified behavior in tests/cpu/meson.build: 新增 SVE/SME 测试专用的严格别名豁免参数 sve_bitpattern_exempt,值为 -fno-strict-aliasing;该范围内其余内容是说明性注释。
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确概括了主要变更:为 SVE/SME 测试目标关闭严格别名优化,以避免 TBAA 删除 SVE 存储并触发误报 SDC。
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (3 skipped: 3 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown

🤖 检视机器人覆盖情况

机器人 状态 判据 佐证
codex ✅ 已检视 作者 login: chatgpt-codex-connector[bot] chatgpt-codex-connector[bot]
CodeRabbit ✅ 已检视 作者 login: coderabbitai[bot],或已完成的 check-run: CodeRabbit coderabbitai[bot]
PR-Agent ✅ 已检视 已完成的 check-run: pr-agent check-run: pr-agent
Greptile ✅ 已检视 作者 login: greptile-apps[bot],或已完成的 check-run app: greptile-apps greptile-apps[bot]

等待上限 900s / 轮询间隔 30s;本检查仅供提示,绝不阻塞合并。

@wangxumarshall
wangxumarshall merged commit 201b179 into main Oct 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant