JIT: Transform SELECT to (folded) bitwise op#128295
Open
BoyBaykiller wants to merge 2 commits into
Open
Conversation
* add SELECT to bitwise transform * add gtFoldAndOrXor and do simple cmp fusion in it (to produce final x >= 0)
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
This was referenced May 17, 2026
Member
this link is not working for me. What is the reason behind bad regressions in both size and perfscore on x64? |
EgorBo
reviewed
May 17, 2026
| } | ||
|
|
||
| if (fusedCmp != GT_NONE && GenTree::Compare(op1->gtGetOp1(), op2->gtGetOp1()) && | ||
| GenTree::Compare(op1->gtGetOp2(), op2->gtGetOp2())) |
Member
There was a problem hiding this comment.
you need to check side-effects here, otherwise you're potentially removing one
Contributor
Author
There was a problem hiding this comment.
I limited it to op->OperIsAnyLocal() || op->OperIsConst() (in my new commit) because I need to do that anyway because of GenTree::Compare. With that check in place, do I still need to check for any side effects?
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.
Fix #123291
SELECT(x == 0, 1, x > 0)->SELECT(x != 0, x > 0, 1)SELECT(x != 0, x > 0, 1)->(x == 0) | (x > 0)gtFoldAndOrXorto fuse cmps:(x == 0) | (x > 0)->x >= 0This overlaps with work that optimizeBools does already. But I think handling it in if-conversion like this is overall better. Perhaps in the future (with the help of this PR and more...) we don't need optimizeBools at all.
I added a general
gtFoldAndOrXortogtFoldExprto fuse the cmps. I didn't add it to morph (e.gfgOptimizeCommutativeArithmetic) because 1. I am not allowed to call that from if-conversion and 2. my understanding of @EgorBo is that we are moving things like this togtFoldExpranyway.Diffs on XARCH look worse because of https://discord.com/channels/143867839282020352/312132327348240384/1502728076243767439
Note the current costing leads to us frequently rejecting cases, for example:
return x == 3 && y == 3;would be transformed to(x == 3 & y == 3)which optimizeBools doesnt do either, but we get:Skipping if-conversion that will evaluate RHS unconditionally at costs 8,1- it only allows up to 7.