gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only)#146641
Draft
eendebakpt wants to merge 5 commits intopython:mainfrom
Draft
gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only)#146641eendebakpt wants to merge 5 commits intopython:mainfrom
eendebakpt wants to merge 5 commits intopython:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR we add inplace binary operations for int type, similar to #146397. A complication compared to the float case is that the int operations can return small ints which should not be modified in place. In this PR we:
PyJitRef_MakeUnique(sym_new_compact_int(ctx));to mark that a symbol is an int that is either unique or one of the small ints._BINARY_OP_ADD_INT_INPLACE(with variations for the other operations) that handles both small ints as input and overflows. An alternative to handling these cases in the opcode would be do deopt. Here we decided not to deopts because this could lead to many deopts.Micro benchmark results:
total += a*b + c(non-small)a*bresulttotal += a + b(non-small)a+bresult is unique, inplace on+=t = a + b(plain assign)+=, not affectedtotal += a*b + c*d(chain)+total += a*b + 1(small int)All values are non-small integers (> 1024) unless noted.
Selected pyperformance benchmarks: