iree-org / iree-org/iree

Add pass to remove redundant `assert` ops.

Open
#8,034 9 comments 0 reactions 0 assignees View on GitHub
compiler/dialects good first issue 🌱 performance ⚡
Dominant language
C++
Stars
3.9k
Forks
1k
Avg merge
4d 16h
Merged PRs (30d)
47

Description

Right now redundant asserts on the same expression will not get elided. We should be able to remove all dominated asserts on the same value: asserts abort and when the first is hit it's not possible for any others to be hit. Something like:
```mlir
assert %0, "first"
cond_br %cond, ^bb2, ^bb3
^bb2:
assert %0, "second"
return
^bb3:
assert %0, "third"
return
```

should just be
```mlir
assert %0, "first"
cond_br %cond, ^bb2, ^bb3
^bb2:
return
^bb3:
return
```

`mlir::DominanceInfo` makes the CFG dominance checks easy, but it's also possible to just walk all asserts in a region and for each assertion condition check all other users to see if they are asserts - the dominance guarantees provided by SSA in CFG give all that's needed.

We'd want to be able to run this at several places in the compiler after anywhere we would locally insert asserts, so having it be a generic pass that runs on an Operation and walks all nested ops would be ideal.

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by locating the existing generic pass entry points and places that locally insert asserts, then review mlir::DominanceInfo for the CFG checks. Done means a reusable operation-walking pass removes dominated asserts on the same value while preserving the first assertion and its message.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.