Missed optimization: `one_hot(decode())` only optimizes for partial-width `decode`
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
When optimizing an isolated `one_hot` of a `decode`: if the `decode` is full-width, we fail to optimize the `one_hot` away, but successfully optimize it if the `decode` is partial-width.
For example:
```
package test
top fn __test__test(x: bits[3]) -> bits[9] {
decoded: bits[8] = decode(x, width=8, id=1)
ret one_hot.2: bits[9] = one_hot(decoded, lsb_prio=true, id=2)
}
```
does not get optimized at all, but if we widen the parameter to 8 bits wide (`x: bits[8]`), it optimizes down to
```
package test
top fn __test__test(x: bits[8]) -> bits[9] {
decoded: bits[8] = decode(x, width=8, id=1)
literal.4: bits[8] = literal(value=0, id=4)
eq.5: bits[1] = eq(decoded, literal.4, id=5)
ret concat.6: bits[9] = concat(eq.5, decoded, id=6)
}
```
Contributor guide
Assessment
This issue has not been assessed yet.