From a3335b259b71cf95eaacb59f0852f092bc597de5 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Mon, 15 May 2017 18:50:53 +0000 Subject: [PATCH] [NewGVN] Fix verification of MemoryPhis in verifyMemoryCongruency(). verifyMemoryCongruency() filters out trivially dead MemoryDef(s), as we find them immediately dead, before moving from TOP to a new congruence class. This fixes the same problem for PHI(s) skipping MemoryPhis if all the operands are dead. Differential Revision: https://reviews.llvm.org/D33044 llvm-svn: 303100 --- lib/Transforms/Scalar/NewGVN.cpp | 13 ++++++++++ test/Transforms/NewGVN/verify-memoryphi.ll | 29 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/Transforms/NewGVN/verify-memoryphi.ll diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp index a8f399d49cc..c70c08dfecd 100644 --- a/lib/Transforms/Scalar/NewGVN.cpp +++ b/lib/Transforms/Scalar/NewGVN.cpp @@ -2549,6 +2549,19 @@ void NewGVN::verifyMemoryCongruency() const { return false; if (auto *MemDef = dyn_cast(Pair.first)) return !isInstructionTriviallyDead(MemDef->getMemoryInst()); + + // We could have phi nodes which operands are all trivially dead, + // so we don't process them. + if (auto *MemPHI = dyn_cast(Pair.first)) { + for (auto &U : MemPHI->incoming_values()) { + if (Instruction *I = dyn_cast(U.get())) { + if (!isInstructionTriviallyDead(I)) + return true; + } + } + return false; + } + return true; }; diff --git a/test/Transforms/NewGVN/verify-memoryphi.ll b/test/Transforms/NewGVN/verify-memoryphi.ll new file mode 100644 index 00000000000..57dbd18986d --- /dev/null +++ b/test/Transforms/NewGVN/verify-memoryphi.ll @@ -0,0 +1,29 @@ +; Skip dead MemoryPhis when performing memory congruency verification +; in NewGVN. +; RUN: opt -S -newgvn %s | FileCheck %s +; REQUIRES: asserts + +; CHECK: define void @tinkywinky() { +; CHECK-NEXT: entry: +; CHECK-NEXT: br i1 false, label %body, label %end +; CHECK: body: +; CHECK-NEXT: store i8 undef, i8* null +; CHECK-NEXT: br label %end +; CHECK: end: +; CHECK-NEXT: ret void +; CHECK-NEXT: } + +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) + +define void @tinkywinky() { +entry: + call void @llvm.lifetime.start.p0i8(i64 4, i8* undef) + br i1 false, label %body, label %end + +body: + call void @llvm.lifetime.start.p0i8(i64 4, i8* undef) + br label %end + +end: + ret void +}