Skip to content
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

Optimization: Fold redundant input parameters loads #81

Closed
tgiphil opened this issue Jul 5, 2014 · 3 comments
Closed

Optimization: Fold redundant input parameters loads #81

tgiphil opened this issue Jul 5, 2014 · 3 comments

Comments

@tgiphil
Copy link
Member

tgiphil commented Jul 5, 2014

A set of virtual registers that are defined only once and loaded from same method input parameter on the stack and that input parameter is never updated, can be folded into a single load.

Example:

In System.String::IndexOfAny(System.Char[])

L_0020 X86.Mov V_6 [System.String] <= this [EBP+4h] [System.String]
L_0021 X86.Mov V_7 [System.Char[]] <= anyOf [EBP+4h] [System.Char[]]
L_0023 X86.Mov V_9 [System.String] <= this [EBP+4h] [System.String]

In this example, the this variable should only be loaded at once into a single virtual register.

The initial load must be placed before all uses from all paths.

A native implementation can place the load in the first block during an early IR stage. This could be helpful for some SSA optimizations.


Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.

@tgiphil tgiphil modified the milestones: 1.2.7 - Bug Fixes and Optimizations, 1.3 - Release Jul 5, 2014
@charsleysa charsleysa modified the milestones: 1.5 - Release, 1.6 - ARM Platform Support Jul 17, 2015
@tgiphil tgiphil modified the milestones: 1.7 - Release, 1.6 - Release Nov 28, 2015
@tgiphil tgiphil self-assigned this Dec 29, 2015
@tgiphil
Copy link
Member Author

tgiphil commented Dec 29, 2015

Plan: Insert load parameter instruction into the first block that dominates all other blocks which use the parameter. The load will move the parameter to a virtual instruction. The load instruction is placed at the end of the block, or if the block contains any existing load instruction, then immediately prior to that instruction. Replace all other load instructions with a move from the virtual instruction.

@tgiphil
Copy link
Member Author

tgiphil commented Dec 29, 2015

Alternative longer-term option: Similar to before, but instead move all the load instructions to the beginning of the first block. And write another optimization stage that re-orders instructions to reduce the distance between assignments (results) and uses. The register allocator will then "best-fit" the live ranges.

@tgiphil tgiphil modified the milestones: 1.9 Release, 1.8 - Release Jul 25, 2017
@tgiphil tgiphil changed the title Fold redundant input parameters loads Optimization: Fold redundant input parameters loads Aug 19, 2017
@tgiphil tgiphil modified the milestones: 1.9 Release, 2.0 Release Jan 19, 2019
@tgiphil
Copy link
Member Author

tgiphil commented Apr 5, 2019

The value numbering optimization implemented this optimization and removes redundant parameter loads.

@tgiphil tgiphil closed this as completed Apr 5, 2019
@tgiphil tgiphil modified the milestones: 2.2 Release, 2.1 Release Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants