[test] Rewrite phi-empty.ll into a unittest
authorArthur Eubanks <aeubanks@google.com>
Tue, 8 Dec 2020 02:57:20 +0000 (18:57 -0800)
committerArthur Eubanks <aeubanks@google.com>
Tue, 8 Dec 2020 17:59:31 +0000 (09:59 -0800)
phi-empty.ll does not pass under the new PM because the NPM runs
-loop-simplify. Running -loop-simplify ends up not reproing
https://llvm.org/PR48296.

Verified that this test fails when 9eb2c011 is reverted.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D92807

llvm/test/Transforms/LoopRotate/phi-empty.ll [deleted file]
llvm/unittests/IR/BasicBlockTest.cpp

diff --git a/llvm/test/Transforms/LoopRotate/phi-empty.ll b/llvm/test/Transforms/LoopRotate/phi-empty.ll
deleted file mode 100644 (file)
index 9337133..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -lcssa -loop-rotate < %s | FileCheck %s
-
-; After rotate, the phi has no operands because it has no predecessors.
-; We might want to delete that instruction instead, but we do not
-; fail/assert by assuming that the phi is invalid IR.
-
-define void @PR48296(i1 %cond) {
-; CHECK-LABEL: @PR48296(
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:    br label [[LOOP:%.*]]
-; CHECK:       loop:
-; CHECK-NEXT:    br i1 [[COND:%.*]], label [[INC:%.*]], label [[LOOP_BACKEDGE:%.*]]
-; CHECK:       loop.backedge:
-; CHECK-NEXT:    br label [[LOOP]]
-; CHECK:       dead:
-; CHECK-NEXT:    unreachable
-; CHECK:       inc:
-; CHECK-NEXT:    br label [[LOOP_BACKEDGE]]
-; CHECK:       return:
-; CHECK-NEXT:    [[R:%.*]] = phi i32
-; CHECK-NEXT:    ret void
-;
-entry:
-  br label %loop
-
-loop:
-  br i1 %cond, label %inc, label %loop
-
-dead:                                        ; No predecessors!
-  br i1 %cond, label %inc, label %return
-
-inc:
-  br label %loop
-
-return:
-  %r = phi i32 [ undef, %dead ]
-  ret void
-}
index fcdc9c2..fa923c9 100644 (file)
 #include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/NoFolder.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Support/SourceMgr.h"
 #include "gmock/gmock-matchers.h"
 #include "gtest/gtest.h"
@@ -165,6 +167,23 @@ TEST(BasicBlockTest, ComesBefore) {
   EXPECT_FALSE(Ret->comesBefore(Ret));
 }
 
+TEST(BasicBlockTest, EmptyPhi) {
+  LLVMContext Ctx;
+
+  Module *M = new Module("MyModule", Ctx);
+  FunctionType *FT = FunctionType::get(Type::getVoidTy(Ctx), {}, false);
+  Function *F = Function::Create(FT, Function::ExternalLinkage, "", M);
+
+  BasicBlock *BB1 = BasicBlock::Create(Ctx, "", F);
+  ReturnInst::Create(Ctx, BB1);
+
+  Type *Ty = Type::getInt32PtrTy(Ctx);
+  BasicBlock *BB2 = BasicBlock::Create(Ctx, "", F);
+  PHINode::Create(Ty, 0, "", BB2);
+  ReturnInst::Create(Ctx, BB2);
+  EXPECT_FALSE(verifyModule(*M, &errs()));
+}
+
 class InstrOrderInvalidationTest : public ::testing::Test {
 protected:
   void SetUp() override {