-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
JIT: optimize (T)x | (T)y to (T)(x | y) #13816
Comments
Hi, |
Exactly, feel free to ask any questions |
Is there a specific folder(s) or set of files that I should consider for making these changes? |
I was also wondering how to approach this issue and came up with the following shell command (types="bool|s?byte|u?short|u?int|u?long"; find . -type f -name "*.cs" -exec grep -En "\(($types)\)\w+\s?(\||&)\s?\(\1\)\w+" {} \; -print) I attached the result sample for the whole |
I've opened a pull request for this: #58727 |
* Better codegen for `(T)x | (T)y` I added a morph pass to fold expressions like `(T)x | (T)y` into `(T)(x | y)`. This results in fewer `movzx` instructions in the asm. Fixes #13816 * Code review updates * Rename function to fgMorphCastedBitwiseOp * Don't fold checked arithmetic * Reuse op1 node for return value * Don't run outside global morphing * Various code style and comment tweaks * Don't call gtGetOp2 if tree was folded. If it was folded, it was folded to a unary (cast) operation and gtGetOp2() will crash. I also tweaked fgMorphCastedBitwiseOp to return nullptr if it didn't do anything (to match behaviour of fgMorphCommutative) * Code review changes for tests * Removed all but one csproj * Added tests for scenarios with overflow, compound exprs, side effects * Add in some asserts and remove a redundant call * fix typo * Code review changes: * Formatting * Use getters instead of fields * set flags on op1 * Fix formatting
Noticed in https://github.com/dotnet/coreclr/issues/27917#issuecomment-557519701 We can optimize some movs away for patterns like
(byte)x | (byte)y
with(byte)(x | y)
, etc.For example:
Current codegen:
Expected codegen (from godbolt and linux abi)
Should be a simple optimization, e.g.:
To:
Also, should work for pointers:
category:cq
theme:basic-cq
skill-level:beginner
cost:small
The text was updated successfully, but these errors were encountered: