Skip to content

Commit d33dcb5

Browse files
authored
[Util] Fix intermittent crash in OptimizeIntArithmeticPass (#20637)
We're seeing intermittent failures in 'sharktank_model_tests :: rocm_hip_w7900' tests on main: - https://github.com/iree-org/iree/actions/runs/14600283542/job/40957129060?pr=20601 - https://github.com/iree-org/iree/actions/runs/14636457142/job/41069048559 - https://github.com/iree-org/iree/actions/runs/14630167718/job/41051068642 The following issue contains more information on the crash and a reproducer: #20636 I am not entirely sure whether this PR contains a fix or a workaround. On one hand, it seems like correctly updating and invalidating all states manually in the transformations should lead to the same result without needing to recompute all states. On the other hand, the `DataFlowSolver` mentions that all analysis states should be erased when IR changes before a re-run (https://github.com/llvm/llvm-project/blob/12a31658ea36cda74157c6b4e6b6c031e39a19c0/mlir/include/mlir/Analysis/DataFlowFramework.h#L320): > /// Steps to re-run a data-flow analysis when IR changes: /// 1. Erase all analysis states as they are no longer valid. /// 2. Re-run the analysis using `initializeAndRun`. Note: I didn't add a test because I don't have a deterministic reproducer. As the crash is intermittent, the reproducer needs to be run a large number of times and will fail once in 10-200 runs maybe. Signed-off-by: Jorn Tuyls <[email protected]>
1 parent 0938623 commit d33dcb5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler/src/iree/compiler/Dialect/Util/Transforms/OptimizeIntArithmetic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ class OptimizeIntArithmeticPass
493493
FrozenRewritePatternSet frozenPatterns(std::move(patterns));
494494
for (int i = 0;; ++i) {
495495
LLVM_DEBUG(dbgs() << " * Starting iteration: " << i << "\n");
496+
// NOTE(jtuyls): Erasing all data flow solver states here should be safe.
497+
// Manually updating and invalidating appropriate states in the
498+
// inserted patterns might speed up the transformation, but this
499+
// currently results in occasional crashes. See
500+
// https://github.com/iree-org/iree/issues/20636.
501+
solver.eraseAllStates();
496502
if (failed(solver.initializeAndRun(op))) {
497503
emitError(op->getLoc()) << "failed to perform int range analysis";
498504
return signalPassFailure();

0 commit comments

Comments
 (0)