llvm / llvm/llvm-project

[MLIR][CSE] Missed `memref.load` elimination across dominated block

Open
#215,986 1 comment 0 reactions 1 assignee Claimed by @ukalappa-mips View on GitHub
mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

MLIR CSE currently misses a simple redundant `memref.load` optimization opportunity across a dominated block. In the following example, the second `memref.load` at line 10 loads from the same memref and the same index as the first load at line 4. The block containing the second load is strictly dominated by the first load, and there are no intervening operations that may write to the memref or otherwise invalidate the loaded value.

### Input Program

**input.mlir**

```llvm
module {
func.func private @composable()
func.func @dominated_block(%arg0: memref, %arg1: index, %arg2: i1, %arg3: i1) -> (i32, i32) {
%0 = memref.load %arg0[%arg1] : memref
cf.cond_br %arg2, ^bb2, ^bb1
^bb1: // pred: ^bb0
call @composable() : () -> ()
cf.br ^bb2
^bb2: // 2 preds: ^bb0, ^bb1
%1 = memref.load %arg0[%arg1] : memref
return %0, %1 : i32, i32
}
}
```

### Command
```bash
mlir-opt input.mlir --canonicalize --cse
```

Version: ef88536bbf62469eb2396d719d237b3191cf4843

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.