Skip to content

Fix subview aliasing for MTE2 sync insertion#669

Open
zhangstevenunity wants to merge 1 commit into
mainfrom
codex/issue667-subview-mte2-region
Open

Fix subview aliasing for MTE2 sync insertion#669
zhangstevenunity wants to merge 1 commit into
mainfrom
codex/issue667-subview-mte2-region

Conversation

@zhangstevenunity
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 enhances the memory alias analysis by introducing StaticMemRegion to track buffer offsets, sizes, and strides. This allows the InsertSync pass to identify disjoint subviews of the same root buffer, thereby eliminating unnecessary synchronization barriers. The implementation includes the extraction of region data from MLIR operations, integration into the MemoryDependentAnalyzer, and expanded debug tracing. Feedback points out that the logic for composing nested subviews is currently flawed, as it fails to correctly incorporate parent strides into offset calculations and incorrectly propagates strides and effective region sizes.

Comment on lines +124 to +125
for (size_t i = 0; i < region.offsets.size(); ++i)
region.offsets[i] += parentRegion->offsets[i];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The composition of subview offsets does not account for the strides of the parent region. When nesting subviews, the absolute offset in the root coordinate system should be calculated as parent_offset + child_offset * parent_stride. The current implementation assumes unit strides, which may lead to incorrect aliasing results for strided subviews.

Suggested change
for (size_t i = 0; i < region.offsets.size(); ++i)
region.offsets[i] += parentRegion->offsets[i];
for (size_t i = 0; i < region.offsets.size(); ++i)
region.offsets[i] = parentRegion->offsets[i] + region.offsets[i] * parentRegion->strides[i];

Comment on lines +127 to +128
if (parentRegion->strides.size() == region.strides.size())
region.strides = parentRegion->strides;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Overwriting the subview's strides with the parent's strides is incorrect if the subview itself introduces a non-unit stride (e.g., via staticStrides in memref.subview). The resulting stride should be the product of the parent's stride and the subview's relative stride. Additionally, the effective size of the region in the root coordinate system should be adjusted to (child_size - 1) * parent_stride + 1 to correctly represent the bounding box in the root buffer when strides are involved.

@reedhecre
Copy link
Copy Markdown

reedhecre commented May 14, 2026

Codex Review

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

  • PR: Fix subview aliasing for MTE2 sync insertion #669 Fix subview aliasing for MTE2 sync insertion
  • Author: zhangstevenunity
  • Base/Head: main / codex/issue667-subview-mte2-region
  • Head SHA: db01401631d7
  • Trigger: PR 有新提交
  • Generated At: 2026-05-14T03:25:13Z
  • Previous Head SHA: 2af1b38673a1
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

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

Log Tail

rm -rf '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/repo'
git clone --branch 'main' --depth 50 'https://github.com/hw-native-sys/PTOAS.git' '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/repo'
cd '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/repo'
git fetch origin 'refs/pull/669/head:pr-669' --depth 50
git fetch origin 'main' --depth 50 || true
git checkout -f 'pr-669'
git rev-parse HEAD
git diff --stat 'origin/main...HEAD' || true
Cloning into '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/repo'...
From https://github.com/hw-native-sys/PTOAS
 * [new ref]         refs/pull/669/head -> pr-669
From https://github.com/hw-native-sys/PTOAS
 * branch            main       -> FETCH_HEAD
Switched to branch 'pr-669'
db01401631d799366b4a631e4dcb4a13e4f99fae
 include/PTO/Transforms/InsertSync/SyncCommon.h     |  24 +-
 .../Transforms/InsertSync/InsertSyncAnalysis.cpp   | 198 ++++++++++++-
 .../InsertSync/MemoryDependentAnalyzer.cpp         | 197 ++++++++++++-
 lib/PTO/Transforms/InsertSync/PTOIRTranslator.cpp  | 315 +++++++++++++++++++--
 ...issue667_strided_subview_mte2_barrier_alias.pto |  34 +++
 .../pto/issue667_subview_mte2_barrier_alias.pto    | 108 +++++++
 6 files changed, 834 insertions(+), 42 deletions(-)
===== END STAGE clone rc=0 @ 2026-05-14 11:25:06 =====

===== STAGE codex-review @ 2026-05-14 11:25:06 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/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/20260514_112502_pr669/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/review_prompt.txt'
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019e2484-3e02-7a92-b8fd-42e733d86dbf
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#669 Fix subview aliasing for MTE2 sync insertion
作者:zhangstevenunity
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 #669 存在问题,并返回 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, request id: d3f16a25-52c6-44c2-b923-acf03e37aa31)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, request id: ceb05470-c2b3-45f9-8ef4-29422ae3b1a6)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, request id: 45c8d93c-d4f7-4a01-89b0-bd740ac1d832)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, request id: 9419509f-0ae6-4868-a029-b18810746eb1)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, request id: 4f39de86-1921-4a26-910b-e92be3f1ab0b)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, request id: 191ed56d-6a3f-4b96-b833-5d7ce6a75dc3
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260514_112502_pr669/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-05-14 11:25:13 =====

@zhangstevenunity zhangstevenunity force-pushed the codex/issue667-subview-mte2-region branch from 2af1b38 to db01401 Compare May 14, 2026 03:20
@zhangstevenunity zhangstevenunity marked this pull request as ready for review May 14, 2026 03:39
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db01401631

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 180 to +182
auto srcType = dyn_cast<MemRefType>(src.getType());
if (!srcType) return {0, 0};
if (!srcType)
return aliasInfo;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle PTO subview offsets before returning on non-memrefs

For pto.subview/PartitionViewOp the source is a TileBufType, so this early MemRefType check returns the default alias info before any offsets or sizes are computed. Because UpdateAliasBufferInfo still records every PTO subview with the parent's base/size, disjoint slices of the same tile all appear to overlap and same-pipe MTE2 barriers are inserted; the new issue667_disjoint_subview_tloads case exercises exactly this path, so the intended PTO subview alias fix is not actually applied to PTO tile subviews.

Useful? React with 👍 / 👎.

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