diff --git a/llvm/test/Transforms/LoopRotate/phi-empty.ll b/llvm/test/Transforms/LoopRotate/phi-empty.ll deleted file mode 100644 index 9337133f89035e..00000000000000 --- a/llvm/test/Transforms/LoopRotate/phi-empty.ll +++ /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 -} diff --git a/llvm/unittests/IR/BasicBlockTest.cpp b/llvm/unittests/IR/BasicBlockTest.cpp index fcdc9c2c07fba3..fa923c90c729e4 100644 --- a/llvm/unittests/IR/BasicBlockTest.cpp +++ b/llvm/unittests/IR/BasicBlockTest.cpp @@ -11,9 +11,11 @@ #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 {