-
Notifications
You must be signed in to change notification settings - Fork 302
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
[CombToSMT] Make result of div-by-zero undefined #7025
Conversation
This adapts the conversion pass to match the recently agreed upon definition for division by zero. Integration tests for circt-lec are added to check the behavior. Note that two syntactically equivalent modules are not considered equivalent if they aren't guaranteed to deterministically produce the same outputs. Alternatively, we could consider two undefined output values equivalent by modeling each value as a pair of a boolean and the bit-vector where the boolean determines if the value is undefined, then two outputs are equivalent if either the boolean is true or the boolean is false and the bitvectors match. There are probably use-cases for both, so maybe we'd want a flag to let the user decide.
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.
Looks good to me!
auto lecOp = builder.create<verif::LogicEquivalenceCheckingOp>(loc); | ||
Value areEquivalent = lecOp.getAreEquivalent(); | ||
builder.cloneRegionBefore(moduleA.getBody(), lecOp.getFirstCircuit(), | ||
lecOp.getFirstCircuit().end()); | ||
builder.cloneRegionBefore(moduleB.getBody(), lecOp.getSecondCircuit(), | ||
lecOp.getSecondCircuit().end()); | ||
|
||
moduleA->erase(); | ||
if (moduleA != moduleB) | ||
moduleB->erase(); | ||
|
||
{ | ||
OpBuilder::InsertionGuard guard(builder); | ||
builder.setInsertionPoint(outputOpA); | ||
builder.create<verif::YieldOp>(loc, outputOpA->getOperands()); | ||
outputOpA->erase(); | ||
builder.setInsertionPoint(outputOpB); | ||
builder.create<verif::YieldOp>(loc, outputOpB->getOperands()); | ||
outputOpB->erase(); | ||
} | ||
|
||
sortTopologically(&lecOp.getFirstCircuit().front()); | ||
sortTopologically(&lecOp.getSecondCircuit().front()); | ||
{ | ||
auto *term = lecOp.getFirstCircuit().front().getTerminator(); | ||
OpBuilder::InsertionGuard guard(builder); | ||
builder.setInsertionPoint(term); | ||
builder.create<verif::YieldOp>(loc, term->getOperands()); | ||
term->erase(); | ||
term = lecOp.getSecondCircuit().front().getTerminator(); | ||
builder.setInsertionPoint(term); | ||
builder.create<verif::YieldOp>(loc, term->getOperands()); | ||
term->erase(); | ||
} | ||
|
||
sortTopologically(&lecOp.getFirstCircuit().front()); | ||
sortTopologically(&lecOp.getSecondCircuit().front()); | ||
|
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.
Is this change just to ensure a module isn't trivially found to be equivalent to itself if its output is undefined?
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 exactly.
This adapts the conversion pass to match the recently agreed upon definition for division by zero. Integration tests for circt-lec are added to check the behavior. Note that two syntactically equivalent modules are not considered equivalent if they aren't guaranteed to deterministically produce the same outputs. Alternatively, we could consider two undefined output values equivalent by modeling each value as a pair of a boolean and the bit-vector where the boolean determines if the value is undefined, then two outputs are equivalent if either the boolean is true or the boolean is false and the bitvectors match. There are probably use-cases for both, so maybe we'd want a flag to let the user decide.