google / google/xls

Assignments with `if` statements are not optimized

Open
#1,475 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

**Describe the bug**
During working on another issue (#1461), we noticed that `if` statements used to assign values based on some condition are not optimized.

**To Reproduce**
1. Cherry pick the commit https://github.com/antmicro/xls/commit/3507f0a9046a3cf997d61f1ad19a469c31df467c (with `slow_if` and `fast_if` samples).
2. Run IR benchmark for both implementations.
3. Observe critical paths:
* `slow_if`
```
Critical path delay: 221ps
Critical path entry count: 2
Critical path:
0ps as synthesized (+0ps); 0.00%
221ps (+221ps): sel.10: bits[1024] = sel(cond, cases=[arg2, arg1], id=10, pos=[(0,2,4)])
0ps (+ 0ps): arg1: bits[1024] = param(arg1, id=2)
```
* `fast_if`
```
Critical path delay: 63ps
Critical path entry count: 4
Critical path:
0ps as synthesized (+0ps); 0.00%
63ps (+ 19ps): or.27: bits[1024] = or(and.25: bits[1024], nor.26: bits[1024], id=27, pos=[(0,8,18)])
44ps (+ 27ps): nor.26: bits[1024] = nor(not.24: bits[1024], mask: bits[1024], id=26, pos=[(0,8,26)])
17ps (+ 17ps): mask: bits[1024] = sign_ext(cond: bits[1], new_bit_count=1024, id=23, pos=[(0,7,15)])
0ps (+ 0ps): cond: bits[1] = param(cond, id=1)
```

**Expected behavior**
The `slow_if`, which uses `if` statement, should be converted to the equivalent of the `fast_if`.

**Environment (this can be helpful for troubleshooting):**
- OS: Arch Linux x86_64
- Kernel version: 6.8.7-arch1-1
- XLS hash: 769ae4e4634387280af5accc3634b65facd1283e (+ cherry picked https://github.com/antmicro/xls/commit/3507f0a9046a3cf997d61f1ad19a469c31df467c)

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.