Skip to content

Commit 56b80bd

Browse files
authored
Merge pull request #4448 from georgerennie/shiftadd_gating
peepopt shiftadd: Only match for sufficiently small constant widths
2 parents da8c8b4 + 41aaaa1 commit 56b80bd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

passes/pmgen/peepopt_shiftadd.pmg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ match add
5353
select port(add, constport).is_fully_const()
5454
define <IdString> varport (constport == \A ? \B : \A)
5555

56+
// only optimize for constants up to a fixed width. this prevents cases
57+
// with a blowup in internal term size and prevents larger constants being
58+
// casted to int incorrectly
59+
select (GetSize(port(add, constport)) <= 24)
60+
5661
// if a value of var is able to wrap the output, the transformation might give wrong results
5762
// an addition/substraction can at most flip one more bit than the largest operand (the carry bit)
5863
// as long as the output can show this bit, no wrap should occur (assuming all signed-ness make sense)

0 commit comments

Comments
 (0)