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

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 2 15:27:06 PST 2023


Carrot created this revision.
Carrot added reviewers: mkazantsev, nikic, reames, hans.
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.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143222

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/2018-06-08-pre-load-dbgloc-no-null-opt.ll
  llvm/test/Transforms/GVN/PRE/pre-load-dbg.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: D143222.494445.patch
Type: text/x-patch
Size: 35986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230202/f0680287/attachment.bin>


More information about the llvm-commits mailing list