[PATCH] D14004: Use the new 'InvariantInfo' property to eliminate redundant loads with --gvn.

Larisse Voufo via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 22 21:09:02 PDT 2015


lvoufo created this revision.
lvoufo added reviewers: dberlin, nlewycky, reames.
lvoufo added a subscriber: llvm-commits.

While processing instructions in GVN, mark global variables and alloca instructions corresponding to each encountered invariant intrinsic call as indicating 'writeonce' memory locations that either have been written into or can be written into again (once). Then, while scanning instructions backwards looking for pointer dependencies for a given load instruction, be sure to temporarily disable or reset the markings, as appropriate. 

This patch is a break-down of (corrected) D13606.


http://reviews.llvm.org/D14004

Files:
  lib/Analysis/MemoryDependenceAnalysis.cpp
  lib/Transforms/Scalar/GVN.cpp

Index: lib/Transforms/Scalar/GVN.cpp
===================================================================
--- lib/Transforms/Scalar/GVN.cpp
+++ lib/Transforms/Scalar/GVN.cpp
@@ -2282,6 +2282,13 @@
   if (isa<DbgInfoIntrinsic>(I))
     return false;
 
+
+  // Also ignore invariant intrinsics, after processing them.
+  if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
+    InvariantInfo &InvInfo = I->getModule()->getInvariantInfo();
+    if (processInvariantIntrinsic(II, InvInfo)) return false;
+  }
+
   // If the instruction can be easily simplified then do so now in preference
   // to value numbering it.  Value numbering often exposes redundancies, for
   // example if it determines that %y is equal to %x then the instruction
Index: lib/Analysis/MemoryDependenceAnalysis.cpp
===================================================================
--- lib/Analysis/MemoryDependenceAnalysis.cpp
+++ lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -494,6 +494,14 @@
 
   const DataLayout &DL = BB->getModule()->getDataLayout();
 
+  // We're about to scan backwards. Preserve the initial invariant_start
+  // intrinsic marking on this load, for subsequent instructions.
+  // First, compute the info to preserve.
+  // Then, actually preserve the info before backward scanning starts.
+  InvariantInfo &InvInfo = BB->getModule()->getInvariantInfo();
+  PreservedInvariantInfo Preserved(isLoad ? QueryInst : nullptr, DL, InvInfo);
+  PreserveInvariantInfo PIO(Preserved);
+
   // Create a numbered basic block to lazily compute and cache instruction
   // positions inside a BB. This is used to provide fast queries for relative
   // position between two instructions in a BB and can be used by
@@ -504,10 +512,15 @@
   while (ScanIt != BB->begin()) {
     Instruction *Inst = --ScanIt;
 
-    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
+    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
       // Debug intrinsics don't (and can't) cause dependencies.
       if (isa<DbgInfoIntrinsic>(II)) continue;
 
+      // Same for invariant intrinsics, which may also unset preserved
+      // invariant info.
+      if (BackwardScanInvariantIntrinsic(II, Preserved, InvInfo)) continue;
+    }
+
     // Limit the amount of scanning we do so we don't end up with quadratic
     // running time on extreme testcases.
     --Limit;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14004.38204.patch
Type: text/x-patch
Size: 2349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151023/1bab8e60/attachment.bin>


More information about the llvm-commits mailing list