-
Notifications
You must be signed in to change notification settings - Fork 220
[opt] Neg canonicalization, abs equals zero optimization. #3627
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
base: main
Are you sure you want to change the base?
Conversation
* Canonicalize `add(not(x), 1) => neg(x)` * Optimize `eq(sel(p, cases=[x, neg(x)]), 0) => eq(x, 0)` (for nez as well)
|
BTW: we've started to think it would be helpful to just add an absolute-value unary operation to XLS IR, so we can canonicalize to it & model it more easily for various optimizations and analyses... without relying on detecting the exact pattern |
|
@ericastor Sounds totally reasonable and definitely like something that's worth us experimenting with! Also generally a pretty type-2 decision since we could always desugar it at some early point in the pipeline if we wanted to. I think there's a natural tension between having fewer primitives (which you'd pick because then because the op representations are more universally present in the IR) vs having more clear composite operations because their aggregate properties are particularly interesting. E.g. for canonicalizing to neg I was wondering if then we'd miss any patterns that were smashing together add(x, $N) on account of negate "laundering" that inside. But it never seems wrong to have a higher level primitive the user can opt to provide the system that "worst case it can do is lower". |
add(not(x), 1) => neg(x)eq(sel(p, cases=[x, neg(x)]), 0) => eq(x, 0)(for nez as well)