Force constant evaluation in slang front-end #9547
Open
+11
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Attempt to fix Issue #9489 which noted a difference in constant evaluation when building with slang at head.
Following the suggestion made by @fabianschuiki in #9489, I replaced
expr.selector().getConstant()bycontext.evaluateConstant(expr.selector())which will force constant evaluation.However, it is unclear to me how to fix the tests defined in
test/Conversion/ImportVerilog/basic.svfor both slang at version 9.1 (which is the default in CIRCT) and for slang at head.Let me be a bit more specific. Here's the piece of SystemVerilog in question:
When running the import test with CIRCT with slang v9.1, we get the currently expected result (only printing the relevant output lines):
If we use slang at head, we get the following output which does not pass the
FileChecktest onbasic.sv:Note how the
moor.extract_ref %z3turns into something withmoore.dyn_extract. According to @fabianschuiki in #9489, this is a consequence of slang not evaluating constants unless they are needed to determine types.This PR contains the suggested fix changing
expr.selector().getConstant()tocontext.evaluateConstant(expr.selector()). So here is the output with these changes with slang at v9.1 showing that the fix does not impact the test:But with slang at head, we get:
So applying the fix will avoid the
moore.dyn_extract, however, the output is different for slang at v9.1 and slang at master. Ideally CIRCT with slang at v9.1 and slang at head would output the same, so I wouldn't have to temporarily patch expected test output on my end.Do you see a way to fix the ImportVerilog code such that the same code gets emitted in both cases?
If not, I can still merge this PR if there's interest in changing the constant evaluation behavior.