[test] Rewrite phi-empty.ll into a unittest

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
This commit is contained in:
Arthur Eubanks 2020-12-07 18:57:20 -08:00
parent 2a06628185
commit 554e6db18e
2 changed files with 19 additions and 39 deletions

View File

@ -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
}

View File

@ -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 {