Skip to content

clear residual op in vpto emit#855

Merged
zhangstevenunity merged 1 commit into
hw-native-sys:mainfrom
Likai-19:vpto_clear_residual_op
Jul 3, 2026
Merged

clear residual op in vpto emit#855
zhangstevenunity merged 1 commit into
hw-native-sys:mainfrom
Likai-19:vpto_clear_residual_op

Conversation

@Likai-19

Copy link
Copy Markdown

问题总结

VPTO lowering pipeline 完成后,module 中残留的 tile 元数据 op 阻塞了 LLVM 导出。这些 op 分为两类:

  1. 语义已完成但未清理的死 oppto.set_valid_shape(始终无 user)、无 user 的 pto.get_valid_shape、无 user 的 pto.treshape、无 user 的 pto.alloc_tile、无 user 的 UnrealizedConversionCastOp

  2. 可被折叠的 cast 链pto.get_valid_shapeUnrealizedConversionCastOp → LLVM i64 的 cast 链,其等价的 LLVM i64 值已存在于原始 pto.alloc_tile 的 valid row/col 属性中,但未被复用。

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces folding for pto.get_validshape intrinsics into materialized tile handles, along with erasing unused pto.set_validshape operations and performing dead code elimination (DCE) on leftover tile-handle view and allocation operations. The review feedback suggests optimizing the iterative DCE implementation to a worklist-based approach to improve complexity from $O(N \times M)$ to $O(N + M)$, and adding a safety check to ensure UnrealizedConversionCastOp has exactly one result before accessing it.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +680 to +699
bool tileDceChanged = true;
while (tileDceChanged) {
tileDceChanged = false;
SmallVector<Operation *, 8> deadTileOps;
func.walk([&](Operation *op) {
if (!op->use_empty())
return;
if (isa<pto::TReshapeOp, pto::MaterializeTileOp, pto::AllocTileOp>(op))
deadTileOps.push_back(op);
else if (auto castOp = dyn_cast<UnrealizedConversionCastOp>(op)) {
if (castOp.getNumOperands() == 1 &&
isa<pto::TileBufType>(castOp.getResult(0).getType()))
deadTileOps.push_back(op);
}
});
for (auto *op : llvm::reverse(deadTileOps)) {
op->erase();
tileDceChanged = true;
}
}

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.

medium

The current iterative DCE implementation performs a full function walk (func.walk) inside a while loop for every level of dead tile operations. For a chain of $N$ dead operations, this results in $O(N \times M)$ complexity (where $M$ is the number of operations in the function).

We can optimize this to $O(N + M)$ by using a worklist-based approach. When an operation is erased, we check if its operands have become dead and add them to the worklist if they match the target types. Additionally, we should verify that UnrealizedConversionCastOp has exactly 1 result before accessing getResult(0) to prevent potential out-of-bounds assertions.

    SmallVector<Operation *, 8> worklist;
    func.walk([&](Operation *op) {
      if (!op->use_empty())
        return;
      if (isa<pto::TReshapeOp, pto::MaterializeTileOp, pto::AllocTileOp>(op)) {
        worklist.push_back(op);
      } else if (auto castOp = dyn_cast<UnrealizedConversionCastOp>(op)) {
        if (castOp.getNumOperands() == 1 && castOp.getNumResults() == 1 &&
            isa<pto::TileBufType>(castOp.getResult(0).getType()))
          worklist.push_back(op);
      }
    });

    while (!worklist.empty()) {
      Operation *op = worklist.pop_back_val();
      SmallVector<Value, 4> operands(op->getOperands());
      op->erase();
      for (Value operand : operands) {
        if (auto *defOp = operand.getDefiningOp()) {
          if (!defOp->use_empty())
            continue;
          if (isa<pto::TReshapeOp, pto::MaterializeTileOp, pto::AllocTileOp>(defOp)) {
            worklist.push_back(defOp);
          } else if (auto castOp = dyn_cast<UnrealizedConversionCastOp>(defOp)) {
            if (castOp.getNumOperands() == 1 && castOp.getNumResults() == 1 &&
                isa<pto::TileBufType>(castOp.getResult(0).getType()))
              worklist.push_back(defOp);
          }
        }
      }
    }

@Likai-19 Likai-19 force-pushed the vpto_clear_residual_op branch from 6c34f51 to eb6e8d3 Compare June 23, 2026 06:40
@reedhecre

reedhecre commented Jun 23, 2026

Copy link
Copy Markdown

Codex Review

该评论由 review 机器人自动更新。

  • PR: clear residual op in vpto emit #855 clear residual op in vpto emit
  • Author: Likai-19
  • Base/Head: main / vpto_clear_residual_op
  • Head SHA: 8a9ab88afe6b
  • Trigger: PR 有新提交
  • Generated At: 2026-07-02T02:45:44Z
  • Previous Head SHA: b8cc3802fb00
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

未生成结构化 findings,因为 review 过程提前失败。

Log Tail


===== STAGE clone @ 2026-07-02 10:45:30 =====
set -euo pipefail
rm -rf '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo'
git clone --branch 'main' --depth 50 'https://github.com/hw-native-sys/PTOAS.git' '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo'
cd '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo'
git fetch origin 'refs/pull/855/head:pr-855' --depth 50
git fetch origin 'main' --depth 50 || true
git checkout -f 'pr-855'
git rev-parse HEAD
git diff --stat 'origin/main...HEAD' || true
Cloning into '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo'...
From https://github.com/hw-native-sys/PTOAS
 * [new ref]           refs/pull/855/head -> pr-855
From https://github.com/hw-native-sys/PTOAS
 * branch              main       -> FETCH_HEAD
Switched to branch 'pr-855'
8a9ab88afe6b91782dcfbeb9fbeeeb659ca8a325
 lib/PTO/Transforms/FoldTileBufIntrinsics.cpp | 74 ++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
===== END STAGE clone rc=0 @ 2026-07-02 10:45:35 =====

===== STAGE codex-review @ 2026-07-02 10:45:35 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo' -s read-only -c 'model_provider="codereview"' -c 'model="gpt-5.4"' -c 'model_reasoning_effort="xhigh"' --output-schema '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f20b7-acc1-7db1-911f-7f6b552e8adf
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#855 clear residual op in vpto emit
作者:Likai-19
base branch:origin/main
head branch:HEAD(当前已 checkout 到 PR head)

要求:
1. 只审查这个 PR 相对 origin/main 的改动,必要时可以看上下文文件。
2. 重点找真实的 correctness / regression / contract mismatch / CI / runtime / compatibility 问题。
3. 不要提纯风格建议,不要提低价值猜测。
4. 严格按优先级输出:
   - P1:高概率会导致错误结果、编译/运行失败、严重回归、发布阻断
   - P2:重要缺陷、行为回归、遗漏校验/测试、较大兼容性问题
   - P3:次要但明确可改的问题
5. 如果没有问题,summary 直接写:未检查到 PR #855 存在问题,并返回 findings=[]。
6. 如果有问题,summary 简洁概括,findings 里每条都要给出:
   - severity
   - title
   - body(说明为什么是问题,尽量具体)
   - file(尽量给相对路径)
   - line(能确定就填整数,否则 null)

建议先查看:
- git status --short
- git diff --stat origin/main...HEAD
- git diff --unified=80 origin/main...HEAD

最终输出必须严格匹配 JSON schema。

mcp startup: no servers
Reconnecting... 1/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a14a50b67f58d7af-LAX, request id: c5d6bbd4-7195-4cd7-a6cf-e140aee6ad20)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a14a50ba08cb1ee0-LAX, request id: 731982ad-1811-49da-a35f-782762d02d4b)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a14a50bedb649cd0-SJC, request id: 1ada3f5f-60ec-4846-9ac8-d4479711a4a8)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a14a50c64aa1cf26-SJC, request id: 4d8eac7a-e189-43d1-bafa-b060e6ba9bfd)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a14a50d29f098f42-SJC, request id: 757b98a7-f2da-4aa7-9f18-16ddabdb816e)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a14a50e82c15d908-LAX, request id: 6f15cd48-954e-4f1e-8fd3-c005ccfaea66
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260702_104528_pr855/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-02 10:45:44 =====

@Likai-19 Likai-19 force-pushed the vpto_clear_residual_op branch from eb6e8d3 to b8cc380 Compare June 29, 2026 06:49
@Likai-19 Likai-19 force-pushed the vpto_clear_residual_op branch from b8cc380 to 8a9ab88 Compare July 2, 2026 02:38
@zhangstevenunity zhangstevenunity merged commit fef4540 into hw-native-sys:main Jul 3, 2026
10 checks passed
@reedhecre

Copy link
Copy Markdown

A3 板测完成(有跳过)

  • 触发方式:merged
  • 源码提交:fef45407dd65
  • 结果汇总:OK 220 / FAIL 0 / SKIP 2
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260703_144517_merged_pr855.log
  • LLVM cache:/home/zhongxuan/ptoas-board-monitor/cache/llvm-project-vpto-llvm21/build-shared
  • 结果 TSV:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260703_144517_merged_pr855.tsv

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.

4 participants