Load coercion is done in two phases:
- Collection of loads: First, we collect the loads that have a dependency with stores. The loads along with their dependencies are added in LoadCoercion map.
- Code generation: Iterate over the loads of LoadCoercion map and replace the loads with the value that we extract from the stores. This is done in implementLoadCoercion().
New instructions are generated during load coercion. In order to eliminate them, we run value numbering for them. For this reason, the load coercion should be completed before the elimination phase.
I don't think modifying the IR directly here and re-running numbering afterwards really fits with the NewGVN model. If the load is congruent to a known expression, couldn't the load be moved to the same congruence class as that expression and then the existing replace and erase logic will take care of the rest?