-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] fix maybeReplaceWithConstant
in IntRangeOptimizations
#133556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir] fix maybeReplaceWithConstant
in IntRangeOptimizations
#133556
Conversation
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesIf a dialect is caching/reusing constants when materializing then such constants might already have
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:
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
|
@llvm/pr-subscribers-mlir-arith Author: Maksim Levental (makslevental) ChangesIf a dialect is caching/reusing constants when materializing then such constants might already have
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:
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
|
Needed to pick up llvm/llvm-project#133556 and fix breakages on main. --------- Co-authored-by: Lei Zhang <[email protected]>
If a dialect is caching/reusing constants when materializing then such constants might already have
IntegerValueRangeLattice
s associated with them and the range endpoint bit widths might not match the new replacement (amongst other possible wackiness).I observed this with
%true = arith.constant true
which was materialized but had an existingIntegerValueRangeLattice
(i.e.,solver.getOrCreateState<dataflow::IntegerValueRangeLattice>
was not uninitalized) with range endpoint bit widths:while the widths of the range end points for something like
%20 = arith.cmpi slt, %19, %c1_i32
(a replacement candidate) would beThus, we should be clearing the analysis state each time a constant is reused.