-
Notifications
You must be signed in to change notification settings - Fork 5.5k
JIT: Add RangeOps::Xor and RangeOps::Not
#126553
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
49c1b40
dda7a50
605b7e3
46043a0
8c60835
5174434
cc0aa1f
2406742
ed8232c
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 |
|---|---|---|
|
|
@@ -479,6 +479,46 @@ struct RangeOps | |
| return Range(Limit(Limit::keUnknown)); | ||
| } | ||
|
|
||
| static Range Xor(const Range& r1, const Range& r2) | ||
|
Member
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. I checked locally and this entire thing has no impact on the SPMI diffs, do we need it then?
Contributor
Author
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. Did you run diffs with #126529 included?
Member
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. Yes
Contributor
Author
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 produces diffs in
Member
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. I think it is better to close it indeed, the entire diffs is 12 contexts, almost all of them in libraries_tests_no_tiered_compilation while the logic is not trivial to verify, so it's mostly just +80 LOC of risky changes as I see it, unless there is a strong argument that it helped you to replace unsafe code with safe somewhere, etc. |
||
| { | ||
| int r1ConstVal; | ||
| int r2ConstVal; | ||
| bool r1IsConstVal = r1.IsSingleValueConstant(&r1ConstVal); | ||
| bool r2IsConstVal = r2.IsSingleValueConstant(&r2ConstVal); | ||
|
|
||
| // Both ranges are single constant values. | ||
| // Example: [5..5] ^ [3..3] = [6..6] | ||
| if (r1IsConstVal && r2IsConstVal) | ||
| { | ||
| return Range(Limit(Limit::keConstant, r1ConstVal ^ r2ConstVal)); | ||
| } | ||
|
|
||
| auto isSubToXorValid = [=](uint64_t cns, Range range) { | ||
| uint64_t lo = (uint64_t)range.LowerLimit().GetConstant(); | ||
| uint64_t hi = (uint64_t)range.UpperLimit().GetConstant(); | ||
| uint64_t knownBits = BitOperations::BitsetFromRange(lo, hi); | ||
|
|
||
| // Zero out bits outside of TYPE. This handles cases that rely on overflow (int.MaxValue - x) | ||
| uint32_t sizeInBits = genTypeSize(TYP_INT) * BITS_PER_BYTE; | ||
| knownBits &= (1ULL << (sizeInBits - 1)) - 1; | ||
|
|
||
| // Can sub be perfomed without carry? | ||
| return (cns & knownBits) == knownBits; | ||
| }; | ||
|
|
||
| // Example: [3..5] ^ [-1..-1] = [-6..-4] | ||
| if (r1IsConstVal && r2.IsConstantRange() && isSubToXorValid(r1ConstVal, r2)) | ||
| { | ||
| return Subtract(r1, r2); | ||
|
Member
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. can you trace for me what does
Member
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. I think we need to check Subtract's result for IsConstantRange (which checks IsValid as well) and return its value, otherwase unknown..unknown.
Contributor
Author
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.
This is equivalent to sub so it will call |
||
| } | ||
| if (r2IsConstVal && r1.IsConstantRange() && isSubToXorValid(r2ConstVal, r1)) | ||
| { | ||
| return Subtract(r2, r1); | ||
| } | ||
|
|
||
| return Range(Limit(Limit::keUnknown)); | ||
| } | ||
|
|
||
| static Range UnsignedMod(const Range& r1, const Range& r2) | ||
| { | ||
| // For X UMOD Y we only handle the case when Y is a fixed positive constant. | ||
|
|
@@ -661,6 +701,12 @@ struct RangeOps | |
| return result; | ||
| } | ||
|
|
||
| static Range Not(const Range& range) | ||
|
Member
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. last I checked Not produced 0 diffs, so we'd better remove it
Contributor
Author
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. #126553 (comment) Here I was talking about 2 large diffs in libraries_tests_no_tiered_compilation caused by NOT handling. Additionally it fixes regressions from my recent transformation (#126529). Example regression in Which this fixes by adding NOT handling (diffs): |
||
| { | ||
| Range cns = Limit(Limit::keConstant, -1); | ||
| return Subtract(cns, range); | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------ | ||
| // EvalRelop: Evaluate the relation between two ranges for the given relop | ||
| // Example: "x >= y" is AlwaysTrue when "x.LowerLimit() >= y.UpperLimit()" | ||
|
|
||

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.
what does this rewrite do
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 just factored out the
BitsetFromRangesince we now use it in morph and rangecheck and adjusted the code a little. We can useBitsetFromRangeto do other stuff for example transform ADD to OR if we wanted.