Skip to content

LATX: optimize AVX and scalar instruction sequences - #438

Draft
luzeng87 wants to merge 6 commits into
lat-opensource:masterfrom
luzeng87:gb603-avx-patterns
Draft

LATX: optimize AVX and scalar instruction sequences#438
luzeng87 wants to merge 6 commits into
lat-opensource:masterfrom
luzeng87:gb603-avx-patterns

Conversation

@luzeng87

@luzeng87 luzeng87 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • combine related AVX shuffle, insert, compare, and arithmetic sequence optimizations
  • recognize repeated scalar additions and three-vector sums only when register use proves the rewrite safe
  • forward scalar arithmetic into FMA operations with explicit data-flow checks
  • preserve VCOMIS/VUCOMIS ordered and unordered flag behavior in translated and LBT paths
  • fuse a guarded scalar pixel update sequence
  • translate VROUNDPS SAE truncation without serialized FCSR reads and writes
  • preserve VINSERTPS inputs when destination and both sources alias

Organization

This PR is stacked on #437. Its branch contains the five #437 prerequisite commits followed by one squashed instruction-sequence commit. Review the final commit for the additions in this PR. The previous cumulative audio and pixel-update PRs are superseded by this grouped PR.

Validation

  • instruction tests cover source/destination aliases, intermediate-register reads, NaN, infinity, signed zero, subnormal values, and VCOMIS unordered cases
  • fixtures run in JIT, cold AOT, and hot AOT modes
  • test and file names describe instructions rather than external workloads
  • DCO sign-offs present on all commits

This PR remains a draft while the grouped branch checks run.

Track VEX.128 destinations whose architectural YMM high halves are known to be zero, and materialize those clears only when a 256-bit operation can observe them or before leaving the TB. This removes repeated LASX clear instructions while preserving signal, JIT, TU, and AOT-visible state.

Add a standalone JIT, cold-AOT, and hot-AOT semantic test for the deferred state.

Signed-off-by: Lu Zeng <luzeng87@gmail.com>

@xiezyang xiezyang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

VINSERTPS 快路径未处理 dest == src1 == src2 的别名情况。
例如 vinsertps xmm4, xmm4, xmm4, 0x9c 会在读取 src1 前覆盖 dest,导致原始 lane 0 丢失。
建议该快路径排除 dest_is_src1,或先保存 src1 后再写目标寄存器。

@xiezyang xiezyang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 包含的 b245da0 存在 3 处 YMM 结果未写回问题:

  • VMASKMOVPS/PD
  • VPBLENDVB
  • VPBLENDW(立即数不是 0 或 0xff 时)
    这些路径均将结果计算到 temp,但只在 XMM 形式下写回 dest。因此 YMM 目标寄存器低 128 位保留旧值,高 128 位被错误清零。
    建议无条件将 temp 写回 dest,并且仅在 XMM 目标时调用 set_high128_xreg_to_zero(dest)。

Signed-off-by: Lu Zeng <luzeng87@gmail.com>
@luzeng87

luzeng87 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

This stack inherits the reproducible mixed XMM/YMM failure from #437 and also has the VINSERTPS destination/source alias issue identified in review. The independent changes need to be submitted and verified by function, without this shared stack. Closing this PR.

@luzeng87 luzeng87 closed this Sep 3, 2026
@luzeng87 luzeng87 reopened this Sep 3, 2026
@luzeng87
luzeng87 marked this pull request as draft September 3, 2026 03:10
Signed-off-by: Lu Zeng <luzeng87@gmail.com>
@luzeng87

luzeng87 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Synced the YMM mask/blend writeback correction as commit dccd7ee83d. This branch had embedded the earlier deferred-zeroing commit, so it required the same full-width destination fix and regression test. The cumulative branch containing this patch passed the focused JIT/cold-AOT/hot-AOT test and lat-pr-fast 24/24 on LoongArch 3A6000. This PR remains a draft.

Signed-off-by: Lu Zeng <luzeng87@gmail.com>
Signed-off-by: Lu Zeng <luzeng87@gmail.com>
Combine independently tested AVX lowering, scalar FMA forwarding, VCOMIS flag handling, pixel updates, and VROUNDPS truncation. Preserve aliased VINSERTPS source values and use instruction-based test names.

Signed-off-by: Lu Zeng <luzeng87@gmail.com>
@luzeng87 luzeng87 changed the title LATX: optimize AVX scalar physics patterns LATX: optimize AVX and scalar instruction sequences Sep 3, 2026
@luzeng87

luzeng87 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Reorganized this branch on top of the current #437 head. All sequence changes are now represented by one squashed commit, e4403b032b; the former cumulative audio and pixel-update PRs are superseded. The VINSERTPS dest == src1 == src2 review case is covered and passes in JIT, cold AOT, and hot AOT modes. Test names now describe instructions and transformations only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants