fix: expand GT_UMOD with constant divisor in morph to enable CSE#127694
Open
mad1081 wants to merge 1 commit intodotnet:mainfrom
Open
fix: expand GT_UMOD with constant divisor in morph to enable CSE#127694mad1081 wants to merge 1 commit intodotnet:mainfrom
mad1081 wants to merge 1 commit intodotnet:mainfrom
Conversation
On XARCH, the transformation of `a % b` into `a - (a / b) * b` was only applied for signed GT_MOD, not unsigned GT_UMOD. This prevented CSE from recognizing the shared division in patterns like `x / 3` and `x % 3`, causing two separate div instructions to be emitted. Extends the existing else-if condition to include GT_UMOD so unsigned modulo with a non-power-of-2 constant divisor is also expanded during morph, matching the behavior already present for GT_MOD.
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
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.
Fixes #119131
Related:
fgMorphModToSubMulDivwas already made to handleGT_UMODcorrectlyx % {pow2_cns}transformation forulongtypes #79676 — unsigned mod support was extended the same way beforeOn XARCH,
fgMorphSmpOpexpandsa % bintoa - (a / b) * bduring morph so that CSE can recognize a shared divisor between a division and a modulo with the same operands. This expansion was gated ontree->OperIs(GT_MOD), so unsigned modulo (GT_UMOD) with a non-power-of-2 constant divisor was never expanded in morph — it wasleft for lowering instead. Since CSE runs before lowering, patterns like:
produced two
divinstructions instead of one.fgMorphModToSubMulDivalready handlesGT_UMODcorrectly (it switches the operator toGT_UDIVand callsCheckDivideByConstOptimized), so the fix is to includeGT_UMODin the condition. Power-of-2 unsigned divisors are unaffected — they are already handled earlier byfgMorphUModToAndSub.Note:
ulongUMOD on XARCH is still blocked by a separate early return that predates this fix and is not addressed here.