Skip to content

LATX: extend EFLAGS reduction across TU calls and native patterns - #431

Draft
LaurenIsACoder wants to merge 7 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/spec2000-eflags-tu-pattern
Draft

LATX: extend EFLAGS reduction across TU calls and native patterns#431
LaurenIsACoder wants to merge 7 commits into
lat-opensource:masterfrom
LaurenIsACoder:lauren/spec2000-eflags-tu-pattern

Conversation

@LaurenIsACoder

Copy link
Copy Markdown
Contributor

Summary

  • analyze EFLAGS requirements through bounded, analysis-only direct-call callee graphs and normal near returns
  • propagate the resulting direct-call liveness through the full TU fixed point, including predecessor TBs
  • let flag reduction consume native pattern metadata for CMP, TEST, BT, SUB, SHR, AND, floating-point Jcc, SETcc, CMOVcc, SBB, and NEG patterns
  • keep indirect edges, missing successors, cross-page callees, locked fallbacks, zero-count shifts, and shared RET code conservative

Design

LATX_EFLAGS_CROSS=0 keeps the existing behavior and LATX_EFLAGS_CROSS=1 enables the direct-call analysis. Callee decoding is bounded and analysis-only: temporary TBs do not enter the execution TU, HBR input, AOT TB set, thunk table, or translation metrics.

The direct-call model assumes the normal ABI discipline that a near RET returns through the slot created by its matching direct CALL. Unknown and indirect control flow still requires all flags. Cross-page callees are intentionally excluded until AOT/SMC can record caller-to-callee page invalidation dependencies.

Pattern discovery runs before flag reduction. A consumer removes only the architectural EFLAGS reads replaced by its native translation; later consumers still preserve the corresponding producer flags. Locked memory operations and masked-zero shifts retain their ordinary EFLAGS paths.

Validation

  • rebased on origin/master at d58864a036f
  • LoongArch release x86_64 build: PASS
  • LoongArch i386 build: PASS
  • 54 focused native-pattern EFLAGS cases: PASS
  • direct-call cross-boundary modes 0 and 1, cold and hot AOT: PASS
  • SPEC CPU2000 integer train, cold AOT generation: 12/12 PASS
  • SPEC CPU2000 integer train, hot AOT execution with cache mapping verified: 12/12 PASS
  • 12 SPEC integer AOT files reduced by 194,760 bytes (0.599%) versus the prior pattern candidate

Runtime movement was sensitive to AOT code layout in individual benchmarks, so this PR claims the verified EFLAGS/code-size reduction and leaves layout tuning to a separate follow-up.

Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
@LaurenIsACoder
LaurenIsACoder force-pushed the lauren/spec2000-eflags-tu-pattern branch from 165d9da to 10151ef Compare August 27, 2026 12:56
@ganjue66da

Copy link
Copy Markdown
Contributor
  • PR 的设计明确要求排除跨页 callee,但实现只比较 TB 起始地址所在页,没有检查整个 TB 是否跨页。
  • 跨页分析 TB 随后会被丢弃,因此第二页发生 SMC 时,只会使 callee 失效,caller 仍保留基于旧代码得到的 EFLAGS 裁剪结果,存在 wrong-code 风险。
  • 现有测试覆盖了调用、pattern 和 AOT,但缺少“callee 跨页并修改第二页”的失效传播测试。
    合并建议:先保守拒绝任何完整范围跨页的分析 TB,并增加跨页 SMC/AOT 回归测试。这个问题修复后,我倾向于 Approve;目前没有发现第二个确定的语义错误。整体可评价为:实现成熟度较高,但差一个正确性边界。

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