[llvm] r311829 - NewGVN: Fix PR33204 - We need to add memory users when we bypass memorydefs for loads, not just when we do it for stores.

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 26 00:37:11 PDT 2017


Author: dannyb
Date: Sat Aug 26 00:37:11 2017
New Revision: 311829

URL: http://llvm.org/viewvc/llvm-project?rev=311829&view=rev
Log:
NewGVN: Fix PR33204 - We need to add memory users when we bypass memorydefs for loads, not just when we do it for stores.

Added:
    llvm/trunk/test/Transforms/NewGVN/pr33204.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=311829&r1=311828&r2=311829&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Sat Aug 26 00:37:11 2017
@@ -1238,9 +1238,9 @@ const Expression *NewGVN::performSymboli
   if (EnableStoreRefinement)
     StoreRHS = MSSAWalker->getClobberingMemoryAccess(StoreAccess);
   // If we bypassed the use-def chains, make sure we add a use.
+  StoreRHS = lookupMemoryLeader(StoreRHS);
   if (StoreRHS != StoreAccess->getDefiningAccess())
     addMemoryUsers(StoreRHS, StoreAccess);
-  StoreRHS = lookupMemoryLeader(StoreRHS);
   // If we are defined by ourselves, use the live on entry def.
   if (StoreRHS == StoreAccess)
     StoreRHS = MSSA->getLiveOnEntryDef();
@@ -1390,9 +1390,13 @@ const Expression *NewGVN::performSymboli
     }
   }
 
-  const Expression *E = createLoadExpression(LI->getType(), LoadAddressLeader,
+  const auto *LE = createLoadExpression(LI->getType(), LoadAddressLeader,
                                              LI, DefiningAccess);
-  return E;
+  // If our MemoryLeader is not our defining access, add a use to the
+  // MemoryLeader, so that we get reprocessed when it changes.
+  if (LE->getMemoryLeader() != DefiningAccess)
+    addMemoryUsers(LE->getMemoryLeader(), OriginalAccess);
+  return LE;
 }
 
 const Expression *
@@ -2025,7 +2029,7 @@ T *NewGVN::getMinDFSOfRange(const Range
 const MemoryAccess *NewGVN::getNextMemoryLeader(CongruenceClass *CC) const {
   // TODO: If this ends up to slow, we can maintain a next memory leader like we
   // do for regular leaders.
-  // Make sure there will be a leader to find
+  // Make sure there will be a leader to find.
   assert(!CC->definesNoMemory() && "Can't get next leader if there is none");
   if (CC->getStoreCount() > 0) {
     if (auto *NL = dyn_cast_or_null<StoreInst>(CC->getNextLeader().first))

Added: llvm/trunk/test/Transforms/NewGVN/pr33204.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/NewGVN/pr33204.ll?rev=311829&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/NewGVN/pr33204.ll (added)
+++ llvm/trunk/test/Transforms/NewGVN/pr33204.ll Sat Aug 26 00:37:11 2017
@@ -0,0 +1,77 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -newgvn -S %s | FileCheck %s
+; Ensure that loads that bypass memory def-use chains get added as users of the new
+; MemoryDef.  Otherwise this test will not pass memory verification because the value
+; of the load will not be reprocessed until verification.
+; ModuleID = 'bugpoint-reduced-simplified.bc'
+source_filename = "bugpoint-output-f242c4f.bc"
+target triple = "x86_64-apple-darwin16.7.0"
+
+ at global = external global i32 #0
+ at global.1 = external global i32 #0
+
+define void @hoge(i32 %arg) {
+; CHECK-LABEL: @hoge(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    br label [[BB2:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    br label [[BB2]]
+; CHECK:       bb2:
+; CHECK-NEXT:    [[TMP:%.*]] = phi i32 [ 0, [[BB1:%.*]] ], [ [[ARG:%.*]], [[BB:%.*]] ]
+; CHECK-NEXT:    br label [[BB6:%.*]]
+; CHECK:       bb3:
+; CHECK-NEXT:    [[TMP4:%.*]] = load i32, i32* @global, !h !0
+; CHECK-NEXT:    unreachable
+; CHECK:       bb6:
+; CHECK-NEXT:    store i32 [[TMP]], i32* @global.1, !h !0
+; CHECK-NEXT:    br i1 undef, label [[BB7:%.*]], label [[BB1]]
+; CHECK:       bb7:
+; CHECK-NEXT:    br i1 undef, label [[BB10:%.*]], label [[BB8:%.*]]
+; CHECK:       bb8:
+; CHECK-NEXT:    br i1 false, label [[BB9:%.*]], label [[BB3:%.*]]
+; CHECK:       bb9:
+; CHECK-NEXT:    store i8 undef, i8* null
+; CHECK-NEXT:    br label [[BB3]]
+; CHECK:       bb10:
+; CHECK-NEXT:    store i32 0, i32* @global, !h !0
+; CHECK-NEXT:    br label [[BB7]]
+;
+bb:
+  br label %bb2
+
+bb1:                                              ; preds = %bb6
+  br label %bb2
+
+bb2:                                              ; preds = %bb1, %bb
+  %tmp = phi i32 [ 0, %bb1 ], [ %arg, %bb ]
+  br label %bb6
+
+bb3:                                              ; preds = %bb9, %bb8
+  %tmp4 = load i32, i32* @global, !h !0
+  %tmp5 = icmp eq i32 %tmp4, 0
+  unreachable
+
+bb6:                                              ; preds = %bb2
+  store i32 %tmp, i32* @global.1, !h !0
+  br i1 undef, label %bb7, label %bb1
+
+bb7:                                              ; preds = %bb10, %bb6
+  br i1 undef, label %bb10, label %bb8
+
+bb8:                                              ; preds = %bb7
+  br i1 false, label %bb9, label %bb3
+
+bb9:                                              ; preds = %bb8
+  call void @widget()
+  br label %bb3
+
+bb10:                                             ; preds = %bb7
+  store i32 0, i32* @global, !h !0
+  br label %bb7
+}
+
+declare void @widget()
+
+attributes #0 = { align=4 }
+
+!0 = !{}




More information about the llvm-commits mailing list