[InstCombine] Signed saturation patterns
[llvm-core.git] / unittests / Analysis / OrderedBasicBlockTest.cpp
blob4cccb38daff35c4a978714d7c24f8e6008ffbd03
1 //===- OrderedBasicBlockTest.cpp - OrderedBasicBlock unit tests -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/OrderedBasicBlock.h"
10 #include "llvm/AsmParser/Parser.h"
11 #include "llvm/IR/BasicBlock.h"
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/Support/DataTypes.h"
16 #include "llvm/Support/SourceMgr.h"
17 #include "gtest/gtest.h"
19 namespace llvm {
20 namespace {
22 class OrderedBasicBlockTest : public testing::Test {
23 protected:
24 LLVMContext C;
26 std::unique_ptr<Module> makeLLVMModule() {
27 const char *ModuleString = R"(define i32 @f(i32 %x) {
28 %add = add i32 %x, 42
29 ret i32 %add
30 })";
31 SMDiagnostic Err;
32 auto foo = parseAssemblyString(ModuleString, Err, C);
33 return foo;
37 TEST_F(OrderedBasicBlockTest, Basic) {
38 auto M = makeLLVMModule();
39 Function *F = M->getFunction("f");
40 BasicBlock::iterator I = F->front().begin();
41 Instruction *Add = &*I++;
42 Instruction *Ret = &*I++;
44 OrderedBasicBlock OBB(&F->front());
45 // Intentionally duplicated to verify cached and uncached are the same.
46 EXPECT_FALSE(OBB.dominates(Add, Add));
47 EXPECT_FALSE(OBB.dominates(Add, Add));
48 EXPECT_TRUE(OBB.dominates(Add, Ret));
49 EXPECT_TRUE(OBB.dominates(Add, Ret));
50 EXPECT_FALSE(OBB.dominates(Ret, Add));
51 EXPECT_FALSE(OBB.dominates(Ret, Add));
52 EXPECT_FALSE(OBB.dominates(Ret, Ret));
53 EXPECT_FALSE(OBB.dominates(Ret, Ret));
56 } // end anonymous namespace
57 } // end namespace llvm