-
Notifications
You must be signed in to change notification settings - Fork 2.6k
JIT: Improve constant folding for bitwise OR #27325
Conversation
|
Thank you for your contribution. As announced in dotnet/coreclr#27549 this repository will be moving to dotnet/runtime on November 13. If you would like to continue working on this PR after this date, the easiest way to move the change to dotnet/runtime is:
|
| /* See if we can fold GT_ADD nodes. */ | ||
|
|
||
| if (oper == GT_ADD) | ||
| if (oper == GT_ADD || oper == GT_OR) |
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.
Why not add GT_MUL, GT_AND and GT_XOR as well?
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.
Also, the comment above should be changed - probably to:
// See if we can fold constants for commutative operators.
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.
@mikedn good point, I was only keeping in mind the Enum and OR case (it's quite popular) didn't want to touch GT_MUL due to possible overflows, but will re-consider thanks to feedback
| } | ||
| else | ||
| { | ||
| cns1->AsIntCon()->SetIconValue(icon1 | icon2); |
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.
Should have an assert that the oper is correct: GT_OR
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.
That follows from the surrounding if-clause
| } | ||
| else | ||
| { | ||
| op2->AsIntConCommon()->SetIconValue(icon1 | icon2); |
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.
Should have an assert that the oper is correct: GT_OR
| /* See if we can fold GT_ADD nodes. */ | ||
|
|
||
| if (oper == GT_ADD) | ||
| if (oper == GT_ADD || oper == GT_OR) |
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.
Also, the comment above should be changed - probably to:
// See if we can fold constants for commutative operators.
| if (oper == GT_ADD || oper == GT_OR) | ||
| { | ||
| /* Fold "((x+icon1)+(y+icon2)) to ((x+y)+(icon1+icon2))" */ | ||
| /* Fold "((x+icon1)+(y+icon2)) to ((x+y)+(icon1+icon2))" same for bitwise OR */ |
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.
The same for bitwise OR is not really very descriptive. Probably would be better to say something like:
// Fold "(x <op> icon1) <op> (y <op> icon2))" to "((x <op> y) <op> (icon1 <op> icon2))"
|
Thank you for feedback, will address it and manually port the PR to the new repo once it lands. |
|
Thank you for your contribution. As announced in #27549 the dotnet/runtime repository will be used going forward for changes to this code base. Closing this PR as no more changes will be accepted into master for this repository. If you’d like to continue working on this change please move it to dotnet/runtime. |
This PR re-uses GT_ADD constant folding logic for GT_OR in morph.cpp.
Example:
Was:
Now:
Jit-diff: