google / google/xls

Remove useless select

Open
#539 0 comments 0 reactions 0 assignees View on GitHub
optimizer
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

From a benchmark we have the following pattern:

```
x = sel(msb(L), cases={L, concat(bits[1]:0, L[:-1])})
```

This is exactly the same as just zero-ing out the msb of L:

```
x = concat(bits[0], L[:-1])
```

This transformation is potentially done by splitting the select. All bits except the msb are the same on either side of the select so the select might be narrowed to something like:

```
tmp0 = sel(msb(L), cases={msb(L), 0})
x = concat{tmp0, L[0:-1]}
```

In this case, other optimizations will simplify tmp0 to bits[1]0 so you end up with:

```
x = concat(0, L[0:-1])
```

This potentially would need some analysis which determines the source of bits. Maybe just tracing through bit_slices, concats initially. Then the analysis could identify selects where most of the bits across all cases are the same. These identical bits could be just concated with the sliced and selected not-the-same bits.

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.