Skip to content

[Sync] prune redundant back-edge sync pairs#653

Open
TaoTao-real wants to merge 3 commits intohw-native-sys:mainfrom
TaoTao-real:codex/backedge-sync-pruning
Open

[Sync] prune redundant back-edge sync pairs#653
TaoTao-real wants to merge 3 commits intohw-native-sys:mainfrom
TaoTao-real:codex/backedge-sync-pruning

Conversation

@TaoTao-real
Copy link
Copy Markdown
Contributor

@TaoTao-real TaoTao-real commented May 11, 2026

Summary

  • Re-enable conservative back-edge redundant sync pruning in RemoveRedundantSync::CheckAllSync.
  • For loop-carried set/wait pairs, split the analysis across the owning loop interval and prune the outer pair when either span already contains a complete inner pair on the same pipe dependency.

Motivation

  • Reduce unnecessary event-id pressure from back-edge syncs and avoid falling back to PIPE_ALL on ping-pong-style kernels.

Testing

  • Existing local ptoas build on the same patch: enable-insert-sync on a2a3_perf_6144_insertsync/gemm_performance.pto generates the expected 44 set/wait and 1 PIPE_ALL shape.

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 enables back-edge pruning in the RemoveRedundantSync pass by checking for redundant synchronization operations within loop bodies and tail spans. The feedback identifies a need for a bounds check when accessing the syncIR_ array to ensure safety. Additionally, the reviewer pointed out that the syncFinder state should be reset between the two CheckRepeatSync calls to ensure the analysis of the head and tail spans remains independent, preventing side effects from affecting the redundancy detection logic.

Comment on lines +108 to +109
auto *loopElement =
dyn_cast<LoopInstanceElement>(syncIR_[forEndIndex.value()].get());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It is safer to verify that the index forEndIndex.value() is within the bounds of syncIR_ before accessing it, consistent with the safety checks used in CheckRepeatSync.

Suggested change
auto *loopElement =
dyn_cast<LoopInstanceElement>(syncIR_[forEndIndex.value()].get());
checkSyncIRIndex(syncIR_, forEndIndex.value());
auto *loopElement =
dyn_cast<LoopInstanceElement>(syncIR_[forEndIndex.value()].get());

Comment on lines +113 to +114
return CheckRepeatSync(begin, loopElement->endId, syncFinder, setFlag) ||
CheckRepeatSync(loopElement->beginId, end, syncFinder, setFlag);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation reuses the syncFinder state between the two CheckRepeatSync calls. If the first call (tail span) finds a set_flag but no matching wait_flag, those bits remain set when checking the second span (head span). This allows a set_flag in the tail to match a wait_flag in the head, effectively detecting loop-carried redundancies.

However, the PR description and code comments state that pruning should occur if either span independently contains a complete inner pair. To strictly adhere to this "either span" logic and avoid side effects between the two independent analysis spans, syncFinder should be reset before the second call.

    if (CheckRepeatSync(begin, loopElement->endId, syncFinder, setFlag)) {
      return true;
    }
    std::fill(syncFinder.begin(), syncFinder.end(), false);
    return CheckRepeatSync(loopElement->beginId, end, syncFinder, setFlag);

@reedhecre
Copy link
Copy Markdown

reedhecre commented May 11, 2026

Codex Review

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

  • PR: [Sync] prune redundant back-edge sync pairs #653 [Sync] prune redundant back-edge sync pairs
  • Author: TaoTao-real
  • Base/Head: main / codex/backedge-sync-pruning
  • Head SHA: 0f85dccf9b69
  • Trigger: PR 有新提交
  • Generated At: 2026-05-11T10:07:31Z
  • Previous Head SHA: e377139b2245
  • Status: completed

Summary

未检查到 PR #653 存在问题

Findings

No issues found.

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