-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fold some HW nodes for constant input #78929
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
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsThis PR setups an initial infrastructure to fold class Prog
{
Vector128<int> Test1() => Vector128.Create(42) | Vector128.Create(1); // is folded to {43;43;43;43}
uint Test2() => Lzcnt.LeadingZeroCount(314); // is folded to 23
}We can extend the list on demand. Main motivation was this case (together with #78783) where I needed
|
8aa7040 to
231ed48
Compare
|
@dotnet/jit-contrib @jakobbotsch can you please take a look - I decided to keep only LZCNT for now (because I needed it) and left a space for future foldings on demand including for vectors. |
src/coreclr/jit/valuenum.cpp
Outdated
| // E.g. for "Sse2.Or(cnsVec1, cnsVec2)" it looks like this: | ||
| // case NI_SSE2_Or: | ||
| //{ | ||
| // simd16_t v1 = GetConstantSimd16(arg0VN); | ||
| // simd16_t v2 = GetConstantSimd16(arg1VN); | ||
| // v1.i64[0] |= v2.i64[0]; | ||
| // v1.i64[1] |= v2.i64[1]; | ||
| // return VNForSimd16Con(v1); | ||
| //} |
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 comment missing some context? Seems out of place
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.
I left an example of a folding for a binary HWIntrinsic VNFunc for someone who decides to implement it here. (E.g. LLVM folds all vector ops)
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.
Do you plan to add it? Otherwise I don't really see a reason to create this empty skeleton which might just stay like this forever.
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.
No near future plans although I did see hits in libraries.pmi for Intrinsics with two VNConstants args.
Ok I'll remove it

This PR setups an initial infrastructure to fold
GT_HWINTRINSICnodes for constant input in VN phase. I've added Lzcnt and Or,Xor,And as examples, e.g.:We can extend the list on demand.
Main motivation was this case (together with #78783) where I needed
BitOperations.Log2to be foldable for constant input (uses Lzcnt under the hood):diffs - only in tests for now but I need this for my upcomining optimizations in C#