Skip to content

Commit dc75783

Browse files
authored
Merge pull request #281 from coredac/fix/nested-loop-live-in-bug
Skip direct-dominating live-in optimization for loop headers
2 parents c99c146 + 89e2142 commit dc75783

9 files changed

Lines changed: 2010 additions & 1398 deletions

File tree

lib/NeuraDialect/Transforms/CanonicalizeLiveInPass.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,25 @@ identifyDirectDominatingLiveIns(Region &region, DominanceInfo &dom_info,
436436
continue;
437437
}
438438

439+
// If the using block is a loop header (has a back-edge), we must NOT treat
440+
// any live-in as a direct dominating live-in. This is because:
441+
// 1. Live-ins from outer scopes have rate mismatch and need PHI_START
442+
// 2. Live-ins from inner blocks are loop-carried dependencies that need PHI
443+
bool using_block_is_loop_header = false;
444+
for (Block *pred : block.getPredecessors()) {
445+
if (dom_info.dominates(&block, pred)) {
446+
using_block_is_loop_header = true;
447+
break;
448+
}
449+
}
450+
451+
if (using_block_is_loop_header) {
452+
// Skips direct dominating live-in optimization for loop headers.
453+
// The value must be promoted to a block argument so that the
454+
// transform-ctrl-to-data-flow pass creates an inner-rate PHI_START.
455+
continue;
456+
}
457+
439458
// Pattern 1: Single-Source-Single-Sink with one conditional branch.
440459
if (isSingleSourceSingleSinkPattern(defining_block, &block, dom_info,
441460
post_dom_info)) {

test/e2e/bicg/bicg_int_kernel.mlir

Lines changed: 181 additions & 266 deletions
Large diffs are not rendered by default.

test/e2e/bicg/bicg_kernel.mlir

Lines changed: 313 additions & 123 deletions
Large diffs are not rendered by default.

test/e2e/fft/fft_kernel.mlir

Lines changed: 529 additions & 416 deletions
Large diffs are not rendered by default.

test/e2e/gemm/gemm_kernel.mlir

Lines changed: 346 additions & 231 deletions
Large diffs are not rendered by default.

test/e2e/gemv/gemv_kernel.mlir

Lines changed: 194 additions & 151 deletions
Large diffs are not rendered by default.

test/e2e/spmv/spmv_kernel.mlir

Lines changed: 382 additions & 130 deletions
Large diffs are not rendered by default.

test/multi-cgra/taskflow/resnet/simple_resnet_tosa.mlir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ module attributes {torch.debug_module_name = "SimpleResNetBlock"} {
521521
// KERNEL-NEXT: }
522522
// KERNEL-NEXT: }
523523

524+
525+
524526
// STREAM: module attributes {torch.debug_module_name = "SimpleResNetBlock"} {
525527
// STREAM-NEXT: memref.global "private" constant @__constant_64xf32 : memref<64xf32> = dense<0.000000e+00> {alignment = 64 : i64}
526528
// STREAM-NEXT: memref.global "private" constant @__constant_64x3x3x64xf32_0 : memref<64x3x3x64xf32> = dense<-0.0151730878> {alignment = 64 : i64}

test/neura/fusion/test.mlir

Lines changed: 44 additions & 81 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)