Skip to content

Commit

Permalink
transforms: (canonicalize) improve dead code elimination (#3252)
Browse files Browse the repository at this point in the history
Moves the dead code elimination into the main pattern rewriting loop of
canonicalization, allowing more canonicalization patterns to be done
after dce.
  • Loading branch information
alexarice authored Oct 7, 2024
1 parent e6d51d8 commit 5243d81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions tests/filecheck/dialects/stencil/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func.func @unused_res(%f1 : !stencil.field<[0,64]xf64>, %f2 : !stencil.field<[0,

// CHECK: func.func @unused_res(%f1 : !stencil.field<[0,64]xf64>, %f2 : !stencil.field<[0,64]xf64>, %of : !stencil.field<[0,64]xf64>) {
// CHECK-NEXT: %t1 = stencil.load %f1 : !stencil.field<[0,64]xf64> -> !stencil.temp<?xf64>
// CHECK-NEXT: %t2 = stencil.load %f2 : !stencil.field<[0,64]xf64> -> !stencil.temp<?xf64>
// CHECK-NEXT: %o1 = stencil.apply(%one = %t1 : !stencil.temp<?xf64>, %two = %t2 : !stencil.temp<?xf64>) -> (!stencil.temp<?xf64>) {
// CHECK-NEXT: %o1 = stencil.apply(%one = %t1 : !stencil.temp<?xf64>) -> (!stencil.temp<?xf64>) {
// CHECK-NEXT: %0 = stencil.access %one[0] : !stencil.temp<?xf64>
// CHECK-NEXT: stencil.return %0 : f64
// CHECK-NEXT: }
Expand Down
8 changes: 5 additions & 3 deletions xdsl/transforms/canonicalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RewritePattern,
)
from xdsl.traits import HasCanonicalizationPatternsTrait
from xdsl.transforms.dead_code_elimination import dce
from xdsl.transforms.dead_code_elimination import RemoveUnusedOperations


class CanonicalizationRewritePattern(RewritePattern):
Expand All @@ -34,5 +34,7 @@ class CanonicalizePass(ModulePass):
name = "canonicalize"

def apply(self, ctx: MLContext, op: builtin.ModuleOp) -> None:
PatternRewriteWalker(CanonicalizationRewritePattern()).rewrite_module(op)
dce(op)
pattern = GreedyRewritePatternApplier(
[RemoveUnusedOperations(), CanonicalizationRewritePattern()]
)
PatternRewriteWalker(pattern).rewrite_module(op)

0 comments on commit 5243d81

Please sign in to comment.