Open quark17 opened 5 days ago
The change in BSC was to stop merging constructors with don't-care values, but this example doesn't have a don't-care. But maybe the BSV parser is introducing something, and maybe this can be fixed in the parser (or the optimization adjusted to recognize specifics of the parser's construction).
BSV code that conditionally updates a variable, like this:
if (rg_1 matches tagged Valid .d1)
tmp_data = d1;
is parsed into internal code that looks like this:
letseq _theResult__ :: Vector 8 T
_theResult__ =
case () of {
_ when Valid d1 <- rg_1 -> ...
_ -> tmp_data
tmp_data = _theResult_
Maybe those don't-cares in the case-arm patterns are relevant?
There appears to have been a regression in October 2020, in revision bad371b3, where @nanavati changed
improveIf
to not optimize constructors with undefined. On theb-lang-discuss
mailing list, an example was attached to message 712 (here), which I have boiled down to a small example:With older BSC (as far back as 2018 at least), it compiles in under a second; with newer BSC (at commit bad371b3 through to the latest release), it fails due to exceeding the max number unfolding steps.
The code is assigning a temporary variable with the values from a vector of registers, then dynamically adjusting elements of the variable's value, and then writing the variable's final values back to the registers. The adjustments are the following:
rg_1
is valid, then replace the temp with that valid valuerg_2
is valid, then update elements from that valid value, when the corresponding value inrg_3
is true (thus usingrg_3
as enable signals for the the data inrg_2
)rg_4
andrg_5
as the data and enable signalsThis should simplify. I have not investigated why the commit broke things or what alternate optimization might help. Ravi, is that something you could look at?
What is interesting is that removing step 1 causes the code to compile again. Steps 2 and 3 are for-loops with vector indexing and updates; but step 1 is just a single if-statement (and no vector indexing).
If the change to
improveIf
is not vital to how BSC evaluates, perhaps a command-line flag can be added, to select the old behavior when people need it?A workaround is to re-write the code to manually push the logic into the elements of the vector: