Track resource update regions and elide/minimize unneeded fills.
- Dominant language
- C++
- Stars
- 3.9k
- Forks
- 1k
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 47
Description
The new stream ops give us enough information to symbolically identify discards:
```mlir
%13 = stream.async.splat %cst_1 : f32 -> !stream.resource<*>{%c296}
%14 = stream.async.update %12, %13[%c0 to %c256] : !stream.resource<*>{%c256} -> %13 as !stream.resource<*>{%c296}
%15 = stream.async.update %arg4, %14[%c256 to %c296] : !stream.resource<*>{%c40} -> %14 as !stream.resource<*>{%c296}
```
Here we know by `[%c0, %c256) + [%c256, %296)` that we are overwriting the entire resource. We should be able to transform this into:
```mlir
%13 = stream.async.alloca : !stream.resource<*>{%c296}
%14 = stream.async.update %12, %13[%c0 to %c256] : !stream.resource<*>{%c256} -> %13 as !stream.resource<*>{%c296}
%15 = stream.async.update %arg4, %14[%c256 to %c296] : !stream.resource<*>{%c40} -> %14 as !stream.resource<*>{%c296}
```
The only value we need to know is constant here is 0 and the rest can be pure equality.
Another case of this is turning the splat into fills if we do have gaps either on the interior or at the tail (common in padding). For example:
```mlir
%13 = stream.async.splat %cst_1 : f32 -> !stream.resource<*>{%c296}
%14 = stream.async.update %12, %13[%c0 to %c256] : !stream.resource<*>{%c256} -> %13 as !stream.resource<*>{%c296}
```
->
```mlir
%13 = stream.async.alloca : !stream.resource<*>{%c296}
%14 = stream.async.update %12, %13[%c0 to %c256] : !stream.resource<*>{%c256} -> %13 as !stream.resource<*>{%c296}
%15 = stream.async.fill %cst_1, %14[%c256 to %c296] : f32 -> %14 as !stream.resource<*>{%c296}
```
Could be done as a canonicalization on update.
Contributor guide
Assessment
This issue has not been assessed yet.