Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds a double negation/not removal optimization to the Value Numbering (VN) phase of the JIT compiler. The optimization removes redundant consecutive NOT or NEG operations (e.g., NOT(NOT(x)) → x, NEG(NEG(x)) → x), matching similar logic already implemented in the global morph phase.
Changes:
- Added double negation removal optimization for VNF_NOT and VNF_NEG operations in VNForFunc
|
I had some similar VN things in #88527 including using De Morgan's laws to push NOT down in boolean VN "trees" ... feel free to poach or ignore. |
| // NOT(AND(x,y)) ==> OR(NOT(x), NOT(y)) | ||
| // | ||
| if (funcApp.m_func == VNFunc(GT_AND)) | ||
| { | ||
| return VNForFunc(typ, VNFunc(GT_OR), VNForFunc(typ, VNFunc(GT_NOT), funcApp.m_args[0]), | ||
| VNForFunc(typ, VNFunc(GT_NOT), funcApp.m_args[1])); | ||
| } |
There was a problem hiding this comment.
Is this one better?
It's going from 2 operations to 3 operations. Same for the one just below (although that one can potentially be 2->2 if ANDN exists).
There was a problem hiding this comment.
I think in fact it produces no diffs so I'll remove it
There was a problem hiding this comment.
Note this is in the "VN" space so number of operations is not that significant. The idea is to propagate nots (either up or down, here down as it's a bit easier to recognize) so they are more likely to reach other nots (again in VN space).
This was part of a bigger PR to build up more complex boolean expressions by back substituting reaching predicates and then to try and simplify them.
AndyAyersMS
left a comment
There was a problem hiding this comment.
I'd prefer the more extensive change here, as helps put VN trees in "canonical" form, but if you want to go back to the simpler change that's fine too.
|
For some reason even from just NOT(NOT(X)) there are size/perfscore regressions 😐 needs to be investigated, closing for now |
A couple of diffs from copying this optimization from global morph to VN
runtime/src/coreclr/jit/morph.cpp
Lines 8131 to 8139 in 79bc254