Skip to content

Conversation

@csa7mdm
Copy link

@csa7mdm csa7mdm commented Dec 14, 2025

Description

This PR addresses issue #74020 by implementing a peephole optimization in JIT Lowering to combine consecutive right shift operations (GT_RSH/GT_RSZ) with constant shift amounts.

Fix

The optimization logic is added to Lowering::LowerShift and handles:

  • Nested shifts of the same operation type: (x >> c1) >> c2 -> x >> (c1 + c2)
  • Nested shifts separated by a cast (common in division lowering): (cast (x >> c1)) >> c2 -> cast (x >> (c1 + c2))

Verification

  • Verified against the scenario reported in the issue where repeated division by constants generates redundant shift instructions.
  • Ensure combined shift count does not exceed type width.

Ahmed Mustafa added 2 commits December 9, 2025 19:52
This change implements a peephole optimization in Lowering::LowerShift to combine consecutive right shifts (RSH/RSZ) with constant amounts. It specifically addresses cases where division optimization introduces redundant shifts, such as (x / c1) / c2.
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 14, 2025
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 14, 2025
@csa7mdm csa7mdm force-pushed the fix/74020-jit-shift-opt branch from bd15d1d to 4aa8c26 Compare December 15, 2025 11:50
@csa7mdm csa7mdm force-pushed the fix/74020-jit-shift-opt branch from 0b10860 to cca8115 Compare December 15, 2025 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants