Skip to content

fix(vmi,ptodsl): correct GS8 lowering and With slot liveness - #1340

Open
Zhendong404 wants to merge 1 commit into
hw-native-sys:mainfrom
mouliangyu:codex/tilekernels-vmi-perf-cast-layouts
Open

fix(vmi,ptodsl): correct GS8 lowering and With slot liveness#1340
Zhendong404 wants to merge 1 commit into
hw-native-sys:mainfrom
mouliangyu:codex/tilekernels-vmi-perf-cast-layouts

Conversation

@Zhendong404

@Zhendong404 Zhendong404 commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR keeps the two changes from tilekernels-vmi-perf that are still in scope, rebased onto the current main:

  • Fix contiguous lowering for compact GS8 loads.
  • Fix PTODSL slot liveness across With/AsyncWith statements, with regression coverage.

The previously included fp8/f16 deinterleaved cast-layout commit has been removed because that issue is being handled separately. No byte-widening vgather changes are included; those overlap with PTOAS PR #1315.

Validation

  • ninja -C build pto-test-opt
  • llvm-lit -v build/test/lit/vmi_new/vmi_to_vpto_group_slot_load.pto — PASS
  • PYTHONPATH=build/python:$PYTHONPATH .venv/bin/python ptodsl/tests/test_jit_compile.py — PASS
  • llvm-lit -q build/test/lit/vmi_new — 514/526 passed; 12 remaining failures are in existing group-slot/optimization paths.

@Zhendong404
Zhendong404 force-pushed the codex/tilekernels-vmi-perf-cast-layouts branch from 3b5bbc9 to 87c8f9a Compare August 25, 2026 06:23
@Zhendong404 Zhendong404 changed the title feat(vmi): preserve assigned cast layouts fix(vmi,ptodsl): correct GS8 lowering and With slot liveness Aug 25, 2026

@mouliangyu mouliangyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

发现两个需要在合入前处理的问题:GS8 的普通 vlds 会把 compact load 的实际读取范围扩大到完整 vector footprint;With/AsyncWith 的 slot liveness 对多 context item 的绑定顺序处理不正确。

验证:LLVM 19.1.7 下重建 pto-test-opt 成功,11 个受影响的 VMI lit 用例通过;新增 PTODSL probe 可单独生成两个 scf.for。现有测试主要验证 IR 形态,未覆盖下面的内存边界和多 item with 场景。

Comment thread lib/PTO/Transforms/VMIToVPTO.cpp Outdated
.create<VsldbOp>(op->getLoc(), vregType,
/*updated_base=*/Type{}, slotBase,
zeroI16, zeroI16, *slotMask)
.create<VldsOp>(op->getLoc(), vregType,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里的 NORM vlds 会读取完整 vector footprint(例如 f32 carrier 为 256B),而 group_slot_load 的语义只保证 compact 的 group scalar 可读。忽略尾部 result lanes 并不会抑制对应内存访问,因此位于 UB 尾部的合法 compact source 可能触发地址越界;原 masked vsldb 至多访问选中的 32B block。请保留受限读取范围,或者明确增加并验证 source 后方 256B 可读的契约,同时补一个 UB 边界 runtime case。现有 docs/designs/vmi-layout-lowering-cases.md 也仍规定此处使用单个 32B vsldb



def _slot_live_before_stmt(stmt, live_after, static_env, static_iters) -> set[_SubscriptSlot]:
if isinstance(stmt, (ast.With, ast.AsyncWith)):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这里没有遵循 Python with item 从左到右求值、每项立即绑定 optional_vars 的语义。例如 with cm() as values, cm(values[0]): pass 中,第二项的 values[0] 不是 with 之前的 live-in,但当前实现会把它加入 context_loads,纯 AST probe 也确实返回该 slot。这可能生成未定义或多余的 loop carry。建议从 body_live 开始逆序遍历 items:先 kill 当前 optional_vars 的绑定,再加入该项 context_expr 的 loads,并覆盖 subscript 绑定目标。

@Zhendong404
Zhendong404 force-pushed the codex/tilekernels-vmi-perf-cast-layouts branch from dbeb86b to 309ad3d Compare August 26, 2026 10:07
@Zhendong404
Zhendong404 force-pushed the codex/tilekernels-vmi-perf-cast-layouts branch from 309ad3d to d112ac0 Compare August 26, 2026 10:31
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