[Mlir-commits] [mlir] [mlir] fix `maybeReplaceWithConstant` in IntRangeOptimizations (PR #133556)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 28 19:44:58 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Maksim Levental (makslevental)
<details>
<summary>Changes</summary>
If a dialect is caching/reusing constants when materializing then such constants might already have `IntegerValueRangeLattice` associated with them and the range endpoint bit widths might not match the new replacement; I observed this with `%true = arith.constant true` which was materialized but had the range endpoint bit widths:
```
umin: 32
umax: 32
smin: 32
smax: 32
```
Thus, we should be clearing the analysis state each time a replacement is made.
---
Full diff: https://github.com/llvm/llvm-project/pull/133556.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp (+5-2)
``````````diff
diff --git a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
index 1cb9453ccf3c9..602d80a45993e 100644
--- a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
@@ -91,8 +91,11 @@ LogicalResult maybeReplaceWithConstant(DataFlowSolver &solver,
if (!constOp)
return failure();
- copyIntegerRange(solver, value, constOp->getResult(0));
- rewriter.replaceAllUsesWith(value, constOp->getResult(0));
+ OpResult res = constOp->getResult(0);
+ if (solver.lookupState<dataflow::IntegerValueRangeLattice>(res))
+ solver.eraseState(res);
+ copyIntegerRange(solver, value, res);
+ rewriter.replaceAllUsesWith(value, res);
return success();
}
} // namespace mlir::dataflow
``````````
</details>
https://github.com/llvm/llvm-project/pull/133556
More information about the Mlir-commits
mailing list