Closed AlexDaniel closed 7 years ago
I'll add a proper peephole optimizer with syntax for a rules files and a code generator that takes rules files and generates the optimizer pass, in addition to or as a replacement for opt_expr. I'll make sure to add this optimization as one of the first rules when this feature becomes available.
I'll update this issue when there is any progress. I hope I will get to it this year, but there is not much year left..
This optimization has been implemented by #292, so I'm now closing this issue. (The generic peephole optimizer stays on my todo list. Not sure when I will get to it though.)
Great! Thanks.
Here is the shortest module to reproduce the issue:
Given that signed numbers are in two's complement, you can use MSB to see if the number is negative or not (
assign o = a[7]
). Synthesis result in this case should be obvious.However, for
a < 0
yosys produces this: (complete command to reproduce exactly the same graph isyosys -p 'synth_xilinx; show -colors 67 -format svg -prefix isneg' isneg.sv
)Sure, I can always optimize it manually, but I find it less readable this way.