ir_equivalence failure after resource_sharing over multiple nested branches
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
#### DSLX code
```
fn target_fn(a: u21, b: u21, c: u21, d: u21) -> u21 {
(a * b) + (c * d) + (a * c) + (b * d)
}
fn wrap(x0: u21) -> u21 {
target_fn(x0, u21:1, u21:0, u21:0)
}
fn helper(inner_sel: bool, x0: u21, y0: u21, y1: u21, y2: u21, y3: u21) -> u21 {
if inner_sel {
wrap(x0)
} else {
target_fn(y0, y1, y2, y3)
}
}
pub fn repro(outer_sel: bool, x0: u21, y0: u21, y1: u21, y2: u21, y3: u21) -> u21 {
if outer_sel {
helper(true, x0, y0, y1, y2, y3)
} else {
target_fn(y0, y1, y2, y3)
}
}
#[test]
fn test_repro() {
assert_eq(repro(false, u21:1, u21:2, u21:3, u21:0, u21:0), u21:6);
assert_eq(repro(true, u21:1, u21:2, u21:3, u21:0, u21:0), u21:1);
}
```
#### .opt.ir with ` --enable_resource_sharing=false`
```
package repro
file_number 0 "repro.x"
top fn __repro__repro(outer_sel: bits[1] id=26, x0: bits[21] id=27, y0: bits[21] id=28, y1: bits[21] id=29, y2: bits[21] id=30, y3: bits[21] id=31) -> bits[21] {
umul.68: bits[21] = umul(y0, y1, id=68, pos=[(0,1,5), (0,17,17)])
umul.69: bits[21] = umul(y2, y3, id=69, pos=[(0,1,15), (0,17,17)])
umul.70: bits[21] = umul(y0, y2, id=70, pos=[(0,1,25), (0,17,17)])
umul.71: bits[21] = umul(y1, y3, id=71, pos=[(0,1,35), (0,17,17)])
add.72: bits[21] = add(umul.68, umul.69, id=72, pos=[(0,1,5), (0,17,17)])
add.73: bits[21] = add(umul.70, umul.71, id=73, pos=[(0,1,5), (0,17,17)])
add.74: bits[21] = add(add.72, add.73, id=74, pos=[(0,1,5), (0,17,17)])
ret sel.35: bits[21] = sel(outer_sel, cases=[add.74, x0], id=35, pos=[(0,14,4)])
}
```
#### .opt.ir with ` --enable_resource_sharing=true`
```
package repro
file_number 0 "repro.x"
top fn __repro__repro(outer_sel: bits[1] id=26, x0: bits[21] id=27, y0: bits[21] id=28, y1: bits[21] id=29, y2: bits[21] id=30, y3: bits[21] id=31) -> bits[21] {
ret x0: bits[21] = param(name=x0, id=27)
}
```
#### equivalent check failure
```
Verified NOT equivalent; results differ for input: bits[1]:0x0, bits[21]:0x9340, bits[21]:0x1c_0a30, bits[21]:0x7_a5d7, bits[21]:0xc_3620, bits[21]:0x1_02a1
```
Contributor guide
Research direction
Start with the DSLX test_repro reproduction and compare the .opt.ir output with resource sharing disabled and enabled. Run the equivalent check using the reported flags and inputs; done means resource sharing preserves repro's behavior and the equivalence check passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100