This is an archive of the discontinued LLVM Phabricator instance.

[GVN] Improve PRE on load instructions
AbandonedPublic

Authored by Carrot on Feb 2 2023, 3:27 PM.

Details

Summary

This patch implements the enhancement proposed by https://github.com/llvm/llvm-project/issues/59312.

Suppose we have following code

   v0 = load %addr
   br %LoadBB

LoadBB:
   v1 = load %addr
   ...

PredBB:
   ...
   br %cond, label %LoadBB, label %SuccBB

SuccBB:
   v2 = load %addr
   ...

Instruction v1 in LoadBB is partially redundant, edge (PredBB, LoadBB) is a critical edge. SuccBB is another successor of PredBB, it contains another load v2 which is identical to v1. Current GVN splits the critical edge (PredBB, LoadBB) and inserts a new load in it. A better method is move the load of v2 into PredBB, then v1 can be changed to a PHI instruction.

If there are two or more similar predecessors, like the test case in the bug entry, current GVN simply gives up because otherwise it needs to split multiple critical edges. But we can move all loads in successor blocks into predecessors.

Compared to last version, this patch contains a check for implicit control flow instruction in function findLoadToHoistIntoPred, so we can avoid moving load across unexpected control flow.

@reames and @hans please try to see if this patch works for your code.

Diff Detail

Event Timeline

Carrot created this revision.Feb 2 2023, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 3:27 PM
Carrot requested review of this revision.Feb 2 2023, 3:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 3:27 PM
reames added a comment.Feb 2 2023, 6:33 PM

Please close this review and reopen the old review with the new diff so that review history is not lost.

Carrot abandoned this revision.Feb 2 2023, 8:06 PM