-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[TableGen] Make !and
and !or
short-circuit
#113963
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1543,6 +1543,23 @@ const Init *BinOpInit::resolveReferences(Resolver &R) const { | |
const Init *lhs = LHS->resolveReferences(R); | ||
const Init *rhs = RHS->resolveReferences(R); | ||
|
||
unsigned Opc = getOpcode(); | ||
if (Opc == AND || Opc == OR) { | ||
// Short-circuit. Regardless whether this is a logical or bitwise | ||
// AND/OR. | ||
// Ideally we could also short-circuit `!or(true, ...)`, but it's | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is up-to-date: in the case of |
||
// difficult to do it right without knowing if rest of the operands | ||
// are all `bit` or not. Therefore, we're only implementing a relatively | ||
// limited version of short-circuit against all ones (`true` is casted | ||
// to 1 rather than all ones before we evaluate `!or`). | ||
if (const auto *LHSi = dyn_cast_or_null<IntInit>( | ||
lhs->convertInitializerTo(IntRecTy::get(getRecordKeeper())))) { | ||
if ((Opc == AND && !LHSi->getValue()) || | ||
(Opc == OR && LHSi->getValue() == -1)) | ||
return LHSi; | ||
} | ||
} | ||
|
||
if (LHS != lhs || RHS != rhs) | ||
return (BinOpInit::get(getOpcode(), lhs, rhs, getType())) | ||
->Fold(R.getCurrentRecord()); | ||
|
Uh oh!
There was an error while loading. Please reload this page.