[PATCH] D63582: [LICM & MSSA] Limit unsafe sinking and hoisting.

Alina Sbirlea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 17:18:24 PDT 2019


asbirlea created this revision.
asbirlea added a reviewer: george.burgess.iv.
Herald added subscribers: Prazek, jlebar.
Herald added a project: LLVM.

The getClobberingMemoryAccess API checks for clobbering accesses in a loop by walking the backedge. This may check if a memory access is being
clobbered by the loop in a previous iteration, depending how smart AA got over the course of the updates in MemorySSA (it does not occur when built from scratch).
If no clobbering access is found inside the loop, it will optimize to an access outside the loop. This however does not mean that access is safe to sink.
Given:

  for i
    load a[i]
    store a[i]

The access corresponding to the load can be optimized to outside the loop, and the load can be hoisted. But it is incorrect to sink it.
In order to sink the load, we'd need to check no Def clobbers the Use in the same iteration. With this patch we currently restrict sinking to either
Defs not existing in the loop, or Defs preceding the load in the same block. An easy extension is to ensure the load (Use) post-dominates all Defs.

Caught by PR42294.

This issue also shed light on the converse problem: hoisting stores in this same scenario would be illegal. With this patch we restrict
hoisting of stores to the case when their corresponding Defs are dominating all Uses in the loop.


Repository:
  rL LLVM

https://reviews.llvm.org/D63582

Files:
  include/llvm/Transforms/Utils/LoopUtils.h
  lib/Transforms/Scalar/LICM.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63582.205721.patch
Type: text/x-patch
Size: 5125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190620/41384a15/attachment.bin>


More information about the llvm-commits mailing list