[Mlir-commits] [mlir] [MLIR] Erase location of folded constants (PR #75415)
Billy Zhu
llvmlistbot at llvm.org
Wed Dec 20 15:07:13 PST 2023
================
@@ -290,15 +296,18 @@ OperationFolder::processFoldResults(Operation *op,
Operation *
OperationFolder::tryGetOrCreateConstant(ConstantMap &uniquedConstants,
Dialect *dialect, Attribute value,
- Type type, Location loc) {
+ Type type) {
// Check if an existing mapping already exists.
auto constKey = std::make_tuple(dialect, value, type);
Operation *&constOp = uniquedConstants[constKey];
- if (constOp)
+ if (constOp) {
+ constOp->setLoc(erasedFoldedLocation);
----------------
zyx-billy wrote:
Oh this is because when people call `tryGetOrCreateConstant`, they expect to be getting an existing constant or materializing a new constant for use elsewhere as a result of a fold.
Say the operation folder originally owned a constant op for index 6. Then somewhere else in the same block, the folder folded (5 + 1) into 6. Now it will call this function to see if we already have a 6. Since it does, the original constant 6 op gets returned to the caller. The caller will use this 6 op to replace the folded op. This means the original 6 op is now deduplicated with the folded op, so will need an erased location. (also see test case `fold_and_merge` below).
More generally, the new contract of this function says that since we know that the caller of this function is going to take whatever constant we return and use somewhere else, the location of this returned op should be erased since it's now a shared constant. The caller should not have to care if this op is reused or materialized, so both cases should return an erased location.
https://github.com/llvm/llvm-project/pull/75415
More information about the Mlir-commits
mailing list