summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Transforms/TestConstantFold.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Transforms/TestConstantFold.cpp')
-rw-r--r--mlir/lib/Transforms/TestConstantFold.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/mlir/lib/Transforms/TestConstantFold.cpp b/mlir/lib/Transforms/TestConstantFold.cpp
index 60407cd49d1..0990d7a73f6 100644
--- a/mlir/lib/Transforms/TestConstantFold.cpp
+++ b/mlir/lib/Transforms/TestConstantFold.cpp
@@ -61,10 +61,18 @@ void TestConstantFold::runOnFunction() {
opsToErase.clear();
auto &f = getFunction();
+ ConstantFoldHelper helper(&f);
- ConstantFoldHelper helper(&f, /*insertAtHead=*/false);
+ // Collect and fold the operations within the function.
+ SmallVector<Operation *, 8> ops;
+ f.walk([&](Operation *op) { ops.push_back(op); });
- f.walk([&](Operation *op) { foldOperation(op, helper); });
+ // Fold the constants in reverse so that the last generated constants from
+ // folding are at the beginning. This creates somewhat of a linear ordering to
+ // the newly generated constants that matches the operation order and improves
+ // the readability of test cases.
+ for (Operation *op : llvm::reverse(ops))
+ foldOperation(op, helper);
// At this point, these operations are dead, remove them.
for (auto *op : opsToErase) {
OpenPOWER on IntegriCloud