Skip to content

Commit

Permalink
peepopt shiftadd: Only match for sufficiently small constant widths
Browse files Browse the repository at this point in the history
This addresses issue YosysHQ#4445
  • Loading branch information
georgerennie committed Jun 12, 2024
1 parent a55e859 commit 41aaaa1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions passes/pmgen/peepopt_shiftadd.pmg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ match add
select port(add, constport).is_fully_const()
define <IdString> varport (constport == \A ? \B : \A)

// only optimize for constants up to a fixed width. this prevents cases
// with a blowup in internal term size and prevents larger constants being
// casted to int incorrectly
select (GetSize(port(add, constport)) <= 24)

// if a value of var is able to wrap the output, the transformation might give wrong results
// an addition/substraction can at most flip one more bit than the largest operand (the carry bit)
// as long as the output can show this bit, no wrap should occur (assuming all signed-ness make sense)
Expand Down

0 comments on commit 41aaaa1

Please sign in to comment.