[PATCH] D141712: [GVN] Improve PRE on load instructions

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 11:12:42 PST 2023


Carrot created this revision.
Carrot added reviewers: mkazantsev, nikic, SixWeining, dyung, chapuni.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
Carrot requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.

This is the second try of D139582 <https://reviews.llvm.org/D139582>, with the following enhancement.

- Don't try to move load instructions across exception handling instructions.
- In function replaceValuesPerBlockEntry ValuesPerBlock[BB] may not be the moved loaded value, in this case we should not replace its value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141712

Files:
  llvm/include/llvm/Transforms/Scalar/GVN.h
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/test/Transforms/GVN/PRE/2011-06-01-NonLocalMemdepMiscompile.ll
  llvm/test/Transforms/GVN/PRE/2017-06-28-pre-load-dbgloc.ll
  llvm/test/Transforms/GVN/PRE/pre-load.ll
  llvm/test/Transforms/GVN/PRE/volatile.ll
  llvm/test/Transforms/GVN/condprop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141712.489074.patch
Type: text/x-patch
Size: 22181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230113/04d2d5e4/attachment.bin>


More information about the llvm-commits mailing list