diff options
| author | Daniel Berlin <dberlin@dberlin.org> | 2017-08-26 07:37:11 +0000 |
|---|---|---|
| committer | Daniel Berlin <dberlin@dberlin.org> | 2017-08-26 07:37:11 +0000 |
| commit | de269f4620ea1a14f5537d361b41b15fb65a9110 (patch) | |
| tree | 331b20f32a49d7b355249375f4113aaee26aaa09 /llvm | |
| parent | 69ec20184831909a3a37605a1d0253a61446fc08 (diff) | |
| download | bcm5719-llvm-de269f4620ea1a14f5537d361b41b15fb65a9110.tar.gz bcm5719-llvm-de269f4620ea1a14f5537d361b41b15fb65a9110.zip | |
NewGVN: Fix PR33204 - We need to add memory users when we bypass memorydefs for loads, not just when we do it for stores.
llvm-svn: 311829
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/NewGVN.cpp | 12 | ||||
| -rw-r--r-- | llvm/test/Transforms/NewGVN/pr33204.ll | 77 |
2 files changed, 85 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 475ee67f531..d260a15707e 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -1238,9 +1238,9 @@ const Expression *NewGVN::performSymbolicStoreEvaluation(Instruction *I) const { 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::performSymbolicLoadEvaluation(Instruction *I) const { } } - 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 &R) const { 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)) diff --git a/llvm/test/Transforms/NewGVN/pr33204.ll b/llvm/test/Transforms/NewGVN/pr33204.ll new file mode 100644 index 00000000000..bd4d7974719 --- /dev/null +++ b/llvm/test/Transforms/NewGVN/pr33204.ll @@ -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" + +@global = external global i32 #0 +@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 = !{} |

