google / google/xls

Array-slice miscompile (bad optimization)

Open
#2,783 5 comments 0 reactions 1 assignee Claimed by @psivaraj View on GitHub
optimizer
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

**Describe the bug**
We've got another miscompile in array-slice simplification, where we're getting incorrect results.

**To Reproduce**
Run the following IR through the `array_simp` pass:
```
package subrosa

top fn function_0(param__3: bits[8] id=4) -> bits[52][1] {
literal.5: bits[52][13] = literal(value=[1501199875790165, 0, 3002399751580330, 0, 4503599627370495, 0, 3002399751580330, 0, 1702093271501567, 2251799813685247, 0, 2251799813685247, 0], id=5)
array_slice.6: bits[52][8] = array_slice(literal.5, param__3, width=8, id=6)
literal.7: bits[1] = literal(value=1, id=7)
ret array_slice.8: bits[52][1] = array_slice(array_slice.6, literal.7, width=1, id=8)
}
```
and evaluate the result before and after with input `bits[8]:0xff`. Pre-`array_simp`, this produces `bits[52]:0` as the output; afterwards, it produces `bits[52]:0x5_5555_5555_5555`.

**Expected behavior**
The results should agree.

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.