Skip to content

Commit

Permalink
[mlir][Transforms] Dialect conversion: Fix bug in `computeNecessaryMa…
Browse files Browse the repository at this point in the history
…terializations` (llvm#104630)

There was a typo in the code path that removes unnecessary
materializations.

Before: Update `opResult` (result of an op different from `user`) in
mapping and remove `user`.
```
replaceMaterialization(rewriterImpl, opResult, inputOperands,
                       inverseMapping);
necessaryMaterializations.remove(materializationOps.lookup(user));
```

After: Update `user->getResults()` in mapping and remove `user`.
```
replaceMaterialization(rewriterImpl, user->getResults(), inputOperands,
                       inverseMapping);
necessaryMaterializations.remove(materializationOps.lookup(user));
```
  • Loading branch information
matthias-springer authored Aug 17, 2024
1 parent e6ceb29 commit cb7614e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlir/lib/Transforms/Utils/DialectConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2680,7 +2680,7 @@ static void computeNecessaryMaterializations(
if (!castOp)
continue;
if (castOp->getResultTypes() == inputOperands.getTypes()) {
replaceMaterialization(rewriterImpl, opResult, inputOperands,
replaceMaterialization(rewriterImpl, user->getResults(), inputOperands,
inverseMapping);
necessaryMaterializations.remove(materializationOps.lookup(user));
}
Expand Down
1 change: 1 addition & 0 deletions mlir/test/Transforms/test-legalize-type-conversion.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func.func @test_block_argument_not_converted() {
func.func @test_signature_conversion_no_converter() {
"test.signature_conversion_no_converter"() ({
// expected-error@below {{failed to legalize unresolved materialization from ('f64') to 'f32' that remained live after conversion}}
// expected-note@below {{see existing live user here}}
^bb0(%arg0: f32):
"test.type_consumer"(%arg0) : (f32) -> ()
"test.return"(%arg0) : (f32) -> ()
Expand Down

0 comments on commit cb7614e

Please sign in to comment.