llvm / llvm/llvm-project

[MLIR] CSE misses an optimization opportunity to eliminate redundant `memref.load`

Open
#218,117 4 comments 0 reactions 0 assignees View on GitHub
missed-optimization mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

MLIR `--cse` misses an optimization opportunity to eliminate a redundant `memref.load` within the same region, even when the first load (at line 3) strictly dominates the second (at line 6) and no intervening writes or side effects exist.

### Input Program

**input.mlir**

```llvm
module {
func.func @domination(%arg0: memref, %arg1: index) -> (i32, i32) {
%0 = memref.load %arg0[%arg1] : memref
cf.br ^bb1
^bb1:
%1 = memref.load %arg0[%arg1] : memref
return %0, %1 : i32, i32
}
}
```

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

Version: 157af9cb0e9cad7df0e8e1d44c78f08ffa7c48e7

Contributor guide

Open the contributing guide

Research direction

Start by running `mlir-opt --cse input.mlir` on the reproducer in the issue and inspect the resulting IR. Trace the MLIR CSE handling for the two `memref.load` operations, using the dominance and side-effect conditions described here. Done means the redundant second load is eliminated and the returned values remain correct.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.