-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix assertion failure in bitOpTree opt #2899
Conversation
…nsider the follwoing case. CCast -> WordSel -> VarRef(leaf)
src/V3Const.cpp
Outdated
if (bit >= m_bitPolarity.width()) { | ||
const V3Number oldPol = std::move(m_bitPolarity); | ||
// oldPol.width() is 8, 16, or 32 because this visitor is called after V3Expand | ||
const int newWidth = oldPol.width() * 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the * 2 for? Below you are only initing up to width, not width*2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is expanding m_bitPolarity.
So newWidth
must be greater than bit + 1
.
Expanding to bit + 1
is maybe ok, but expanding by 2x is better because
- CCast will cast to such bitwidth anyway (33 bit width has to be 64 in C++)
- can avoid frequent expansion
The expanded m_bitPolarity
is filled by 'X', then copy from oldPol
.
Lines 120 to 126 in 6af31c3
m_bitPolarity.setAllBitsX(); | |
for (int i = 0; i < oldPol.width(); ++i) { | |
if (oldPol.bitIs0(i)) | |
m_bitPolarity.setBit(i, '0'); | |
else if (oldPol.bitIs1(i)) | |
m_bitPolarity.setBit(i, '1'); | |
} |
This is matches the initialization inf ctor.
Lines 179 to 183 in 6af31c3
VarInfo(ConstBitOpTreeVisitor* parent, AstVarRef* refp) | |
: m_parentp(parent) | |
, m_refp(refp) | |
, m_bitPolarity(refp, refp->isWide() ? VL_EDATASIZE : refp->width()) { | |
m_bitPolarity.setAllBitsX(); |
Thanks for highlighting this code. I noticed that m_bitPolarity
has to be expanded more than 2x in some cases. (e.g. 8 to 32)
So I pushed 6af31c3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wsnyder Does the comment above answer your question ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks
With the latest master , All testcase passed. #2891 |
Second try to repair #2891
Ast such as below caused the issue:
The bitwidth of a variable considering casts in tree requires traversing backp().
Instead of doing so, the width of m_bitPolarity is dynamically expanded if necessary.
I ran ext_tests with
--trace
and--coverage
enabled.