[all-commits] [llvm/llvm-project] 156655: [mlir] Avoid rewriting unreachable blocks in the g...

Vijay Kandiah via All-commits all-commits at lists.llvm.org
Fri Sep 25 05:10:44 PDT 2026


  Branch: refs/heads/users/mamini/greedy-rewrite-reachability
  Home:   https://github.com/llvm/llvm-project
  Commit: 1566559ad5c6e4bf4a74e258608d4f32fe598121
      https://github.com/llvm/llvm-project/commit/1566559ad5c6e4bf4a74e258608d4f32fe598121
  Author: Vijay Kandiah <vkandiah at nvidia.com>
  Date:   2026-09-25 (Fri, 25 Sep 2026)

  Changed paths:
    M mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h
    M mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
    M mlir/test/Transforms/canonicalize-dce.mlir
    A mlir/test/Transforms/greedy-cfg-reachability.mlir
    M mlir/test/Transforms/test-strict-pattern-driver.mlir
    M mlir/test/lib/Dialect/Test/TestPatterns.cpp

  Log Message:
  -----------
  [mlir] Avoid rewriting unreachable blocks in the greedy driver

A rewrite can disconnect a block after the iteration's initial CFG sweep.
Track reachability through rewriter notifications and skip worklist
operations in unreachable blocks until the next iteration removes them.

Cache reachability per region. Compare the final successors of changed
blocks after each rewrite, preserving the cache for successor-equivalent
changes and block merges that keep surviving blocks reachable. Recompute for
other CFG changes. This avoids repeated full CFG scans during branch
canonicalization.

Single-block regions return before cache lookup or CFG traversal. Before the
cache bookkeeping simplification, in the same Release build, canonicalizing
32,000 sibling single-block regions took 22.8 ms versus 21.9 ms with the
parent driver. With 16,000 regions containing folds, the times were 35.7 ms
and 34.3 ms, respectively. Nesting to 256 levels showed no measurable
difference.

Before that simplification, on a synthetic CFG chain whose conditional
branches have identical successors, median CanonicalizerPass times with
region simplification disabled were 0.3, 0.7, 1.3, and 2.5 ms in the parent
commit, versus 0.6, 1.2, 2.5, and 5.0 ms with this commit, for 500, 1,000,
2,000, and 4,000 blocks respectively. Both used the same Release build.

Cover inserted and redirected blocks, blocks connected before rewrite
completion, nested regions, and explicit op-list behavior. Exercise updates
to populated caches and observe whether affected operations are rewritten.
Invalidate the source cache on cross-region block moves so a subsequent
erasure cannot leave a dangling pointer. Share the traversal, use the
successor map as the reachable set, and use set membership for successors.

Validate connected blocks within a single greedy iteration. Avoid snapshots
of uncached blocks and redundant erased-block validation. Document that
skipped operations are not automatically retried if a later rewrite makes
their block reachable.

Validate and update changed blocks in one pass without a temporary successor
map. Derive the containing region in markBlockChanged. Test same-region block
merges that preserve successors and merges that disconnect a successor.

Assisted-by: Codex



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list