[llvm] r373811 - Add a unittest to verify for assumption cache
Aditya Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 16:36:59 PDT 2019
Author: hiraditya
Date: Fri Oct 4 16:36:59 2019
New Revision: 373811
URL: http://llvm.org/viewvc/llvm-project?rev=373811&view=rev
Log:
Add a unittest to verify for assumption cache
Reviewers: vsk, tejohnson
Reviewed By: vsk
Differential Revision: https://reviews.llvm.org/D68095
Modified:
llvm/trunk/unittests/Transforms/Utils/CodeExtractorTest.cpp
Modified: llvm/trunk/unittests/Transforms/Utils/CodeExtractorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/CodeExtractorTest.cpp?rev=373811&r1=373810&r2=373811&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/CodeExtractorTest.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/CodeExtractorTest.cpp Fri Oct 4 16:36:59 2019
@@ -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, StoreOutputInvokeRes
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
More information about the llvm-commits
mailing list