[Canonicalizer] Process regions top-down instead of bottom up & reuse existing constants.
authorChris Lattner <clattner@nondot.org>
Sun, 14 Mar 2021 20:14:48 +0000 (13:14 -0700)
committerChris Lattner <clattner@nondot.org>
Mon, 15 Mar 2021 01:21:42 +0000 (18:21 -0700)
commitb5d9a3c92358349d5444ab28de8ab5b2bee33a01
tree2a5b816575dfcd70ff64421c8618eb626bcf2829
parent6e303a982d6ce5a281ba95238ed376a2caf27a52
[Canonicalizer] Process regions top-down instead of bottom up & reuse existing constants.

Two changes:
 1) Change the canonicalizer to walk the function in top-down order instead of
    bottom-up order.  This composes well with the "top down" nature of constant
    folding and simplification, reducing iterations and re-evaluation of ops in
    simple cases.
 2) Explicitly enter existing constants into the OperationFolder table before
    canonicalizing.  Previously we would "constant fold" them and rematerialize
    them, wastefully recreating a bunch fo constants, which lead to pointless
    memory traffic.

Both changes together provide a 33% speedup for canonicalize on some mid-size
CIRCT examples.

One artifact of this change is that the constants generated in normal pattern
application get inserted at the top of the function as the patterns are applied.
Because of this, we get "inverted" constants more often, which is an aethetic
change to the IR but does permute some testcases.

Differential Revision: https://reviews.llvm.org/D98609
23 files changed:
mlir/include/mlir/Transforms/FoldUtils.h
mlir/lib/Transforms/Utils/FoldUtils.cpp
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
mlir/test/Conversion/StandardToSPIRV/legalization.mlir
mlir/test/Conversion/VectorToSCF/vector-to-loops.mlir
mlir/test/Dialect/Affine/canonicalize.mlir
mlir/test/Dialect/Linalg/sparse_2d.mlir
mlir/test/Dialect/Linalg/transform-patterns.mlir
mlir/test/Dialect/Quant/convert-const.mlir
mlir/test/Dialect/SCF/canonicalize.mlir
mlir/test/Dialect/SPIRV/Transforms/canonicalize.mlir
mlir/test/Dialect/Tensor/canonicalize.mlir
mlir/test/Dialect/Vector/canonicalize.mlir
mlir/test/Dialect/Vector/vector-contract-transforms.mlir
mlir/test/Dialect/Vector/vector-flat-transforms.mlir
mlir/test/Dialect/Vector/vector-transfer-full-partial-split.mlir
mlir/test/Dialect/Vector/vector-transfer-unroll.mlir
mlir/test/Dialect/Vector/vector-transforms.mlir
mlir/test/Transforms/canonicalize.mlir
mlir/test/Transforms/parallel-loop-collapsing.mlir
mlir/test/Transforms/single-parallel-loop-collapsing.mlir
mlir/test/Transforms/test-canonicalize.mlir
mlir/test/mlir-tblgen/pattern.mlir