[PATCH] D66603: # Enter a commit message. # # Changes: # # llvm/lib/Transforms/Scalar/GVN.cpp

Shreyansh Chouhan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 10:29:12 PDT 2019


BK1603 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

This commit attempts on fixing bug #20811 [https://bugs.llvm.org/show_bug.cgi?id=20811]

The commit changes the function AnalyzeLoadAvailability in the following manner:

Currently, the function considers a load after lifetime end to be a instruction clobbered dependency,
and returns false, without populating Res.

The commit makes the function return true if a load is performed after the lifetime of a pointer has ended
and populates Res with undef (just as in the case of a load placed immediately after lifetime start.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66603

Files:
  llvm/lib/Transforms/Scalar/GVN.cpp


Index: llvm/lib/Transforms/Scalar/GVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVN.cpp
+++ llvm/lib/Transforms/Scalar/GVN.cpp
@@ -822,6 +822,12 @@
   return false;
 }
 
+static bool isLifetimeEnd(const Instruction *Inst) {
+  if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
+    return II->getIntrinsicID() == Intrinsic::lifetime_end;
+  return false;
+}
+
 /// Try to locate the three instruction involved in a missed
 /// load-elimination case that is due to an intervening store.
 static void reportMayClobberedLoad(LoadInst *LI, MemDepResult DepInfo,
@@ -864,6 +870,15 @@
   const DataLayout &DL = LI->getModule()->getDataLayout();
 
   Instruction *DepInst = DepInfo.getInst();
+
+  // Loading the allocation -> undef.
+  if (isa<AllocaInst>(DepInst) || isMallocLikeFn(DepInst, TLI) ||
+      // Loading immediately after lifetime begin or end -> undef.
+      isLifetimeStart(DepInst) || isLifetimeEnd(DepInst)) {
+    Res = AvailableValue::get(UndefValue::get(LI->getType()));
+    return true;
+  }
+
   if (DepInfo.isClobber()) {
     // If the dependence is to a store that writes to a superset of the bits
     // read by the load, we can extract the bits we need for the load from the
@@ -923,14 +938,6 @@
   }
   assert(DepInfo.isDef() && "follows from above");
 
-  // Loading the allocation -> undef.
-  if (isa<AllocaInst>(DepInst) || isMallocLikeFn(DepInst, TLI) ||
-      // Loading immediately after lifetime begin -> undef.
-      isLifetimeStart(DepInst)) {
-    Res = AvailableValue::get(UndefValue::get(LI->getType()));
-    return true;
-  }
-
   // Loading from calloc (which zero initializes memory) -> zero
   if (isCallocLikeFn(DepInst, TLI)) {
     Res = AvailableValue::get(Constant::getNullValue(LI->getType()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66603.216659.patch
Type: text/x-patch
Size: 1819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190822/aa4d40b3/attachment.bin>


More information about the llvm-commits mailing list