diff options
author | Aditya Kumar <hiraditya@msn.com> | 2019-10-04 23:36:59 +0000 |
---|---|---|
committer | Aditya Kumar <hiraditya@msn.com> | 2019-10-04 23:36:59 +0000 |
commit | 50afaa9d34d6447b04286335d9e85bd70637ecff (patch) | |
tree | f5a48f4b03078a3d5c5522624703b8ca78edc507 /llvm/unittests/Transforms/Utils | |
parent | 4e5d9e120be36a4518c85383d5231db8416c2d96 (diff) | |
download | bcm5719-llvm-50afaa9d34d6447b04286335d9e85bd70637ecff.tar.gz bcm5719-llvm-50afaa9d34d6447b04286335d9e85bd70637ecff.zip |
Add a unittest to verify for assumption cache
Reviewers: vsk, tejohnson
Reviewed By: vsk
Differential Revision: https://reviews.llvm.org/D68095
llvm-svn: 373811
Diffstat (limited to 'llvm/unittests/Transforms/Utils')
-rw-r--r-- | llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp b/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp index 8b86951fa5e..9213be72697 100644 --- a/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp +++ b/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp @@ -8,6 +8,7 @@ #include "llvm/Transforms/Utils/CodeExtractor.h" #include "llvm/AsmParser/Parser.h" +#include "llvm/Analysis/AssumptionCache.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Instructions.h" @@ -225,4 +226,55 @@ TEST(CodeExtractor, StoreOutputInvokeResultInExitStub) { EXPECT_FALSE(verifyFunction(*Func)); } +TEST(CodeExtractor, ExtractAndInvalidateAssumptionCache) { + LLVMContext Ctx; + SMDiagnostic Err; + std::unique_ptr<Module> M(parseAssemblyString(R"ir( + target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" + target triple = "aarch64" + + %b = type { i64 } + declare void @g(i8*) + + declare void @llvm.assume(i1) #0 + + define void @test() { + entry: + br label %label + + label: + %0 = load %b*, %b** inttoptr (i64 8 to %b**), align 8 + %1 = getelementptr inbounds %b, %b* %0, i64 undef, i32 0 + %2 = load i64, i64* %1, align 8 + %3 = icmp ugt i64 %2, 1 + br i1 %3, label %if.then, label %if.else + + if.then: + unreachable + + if.else: + call void @g(i8* undef) + store i64 undef, i64* null, align 536870912 + %4 = icmp eq i64 %2, 0 + call void @llvm.assume(i1 %4) + unreachable + } + + attributes #0 = { nounwind willreturn } + )ir", + Err, Ctx)); + + assert(M && "Could not parse module?"); + Function *Func = M->getFunction("test"); + SmallVector<BasicBlock *, 1> Blocks{ getBlockByName(Func, "if.else") }; + AssumptionCache AC(*Func); + CodeExtractor CE(Blocks, nullptr, false, nullptr, nullptr, &AC); + EXPECT_TRUE(CE.isEligible()); + + Function *Outlined = CE.extractCodeRegion(); + EXPECT_TRUE(Outlined); + EXPECT_FALSE(verifyFunction(*Outlined)); + EXPECT_FALSE(verifyFunction(*Func)); + EXPECT_FALSE(CE.verifyAssumptionCache(*Func, &AC)); +} } // end anonymous namespace |