summaryrefslogtreecommitdiff
path: root/unittests/IR
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/IR')
-rw-r--r--unittests/IR/AsmWriterTest.cpp2
-rw-r--r--unittests/IR/ConstantRangeTest.cpp17
-rw-r--r--unittests/IR/ConstantsTest.cpp4
-rw-r--r--unittests/IR/DebugTypeODRUniquingTest.cpp2
-rw-r--r--unittests/IR/DominatorTreeTest.cpp52
-rw-r--r--unittests/IR/IRBuilderTest.cpp2
-rw-r--r--unittests/IR/MetadataTest.cpp2
-rw-r--r--unittests/IR/ModuleTest.cpp2
-rw-r--r--unittests/IR/PassManagerTest.cpp2
-rw-r--r--unittests/IR/PatternMatch.cpp2
-rw-r--r--unittests/IR/UserTest.cpp2
-rw-r--r--unittests/IR/ValueTest.cpp2
-rw-r--r--unittests/IR/VerifierTest.cpp4
13 files changed, 82 insertions, 13 deletions
diff --git a/unittests/IR/AsmWriterTest.cpp b/unittests/IR/AsmWriterTest.cpp
index c7e7bb5c9f0f..55c2a70e21f5 100644
--- a/unittests/IR/AsmWriterTest.cpp
+++ b/unittests/IR/AsmWriterTest.cpp
@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp
index c6c9bf6d6b50..0292f60fe332 100644
--- a/unittests/IR/ConstantRangeTest.cpp
+++ b/unittests/IR/ConstantRangeTest.cpp
@@ -187,6 +187,23 @@ TEST_F(ConstantRangeTest, Trunc) {
EXPECT_EQ(TOne, ConstantRange(One.getLower().trunc(10),
One.getUpper().trunc(10)));
EXPECT_TRUE(TSome.isFullSet());
+ EXPECT_TRUE(TWrap.isFullSet());
+
+ // trunc([2, 5), 3->2) = [2, 1)
+ ConstantRange TwoFive(APInt(3, 2), APInt(3, 5));
+ EXPECT_EQ(TwoFive.truncate(2), ConstantRange(APInt(2, 2), APInt(2, 1)));
+
+ // trunc([2, 6), 3->2) = full
+ ConstantRange TwoSix(APInt(3, 2), APInt(3, 6));
+ EXPECT_TRUE(TwoSix.truncate(2).isFullSet());
+
+ // trunc([5, 7), 3->2) = [1, 3)
+ ConstantRange FiveSeven(APInt(3, 5), APInt(3, 7));
+ EXPECT_EQ(FiveSeven.truncate(2), ConstantRange(APInt(2, 1), APInt(2, 3)));
+
+ // trunc([7, 1), 3->2) = [3, 1)
+ ConstantRange SevenOne(APInt(3, 7), APInt(3, 1));
+ EXPECT_EQ(SevenOne.truncate(2), ConstantRange(APInt(2, 3), APInt(2, 1)));
}
TEST_F(ConstantRangeTest, ZExt) {
diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp
index 7a8a3045a0d4..ccffa50bf133 100644
--- a/unittests/IR/ConstantsTest.cpp
+++ b/unittests/IR/ConstantsTest.cpp
@@ -7,15 +7,15 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/Constants.h"
+#include "llvm-c/Core.h"
+#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/SourceMgr.h"
-#include "llvm-c/Core.h"
#include "gtest/gtest.h"
namespace llvm {
diff --git a/unittests/IR/DebugTypeODRUniquingTest.cpp b/unittests/IR/DebugTypeODRUniquingTest.cpp
index 7cf1cd22a2fb..7eb08e24b408 100644
--- a/unittests/IR/DebugTypeODRUniquingTest.cpp
+++ b/unittests/IR/DebugTypeODRUniquingTest.cpp
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/LLVMContext.h"
#include "gtest/gtest.h"
using namespace llvm;
diff --git a/unittests/IR/DominatorTreeTest.cpp b/unittests/IR/DominatorTreeTest.cpp
index d2062839a734..232f0cbd4ed9 100644
--- a/unittests/IR/DominatorTreeTest.cpp
+++ b/unittests/IR/DominatorTreeTest.cpp
@@ -257,3 +257,55 @@ TEST(DominatorTree, Unreachable) {
DT->verifyDomTree();
});
}
+
+TEST(DominatorTree, NonUniqueEdges) {
+ StringRef ModuleString =
+ "define i32 @f(i32 %i, i32 *%p) {\n"
+ "bb0:\n"
+ " store i32 %i, i32 *%p\n"
+ " switch i32 %i, label %bb2 [\n"
+ " i32 0, label %bb1\n"
+ " i32 1, label %bb1\n"
+ " ]\n"
+ " bb1:\n"
+ " ret i32 1\n"
+ " bb2:\n"
+ " ret i32 4\n"
+ "}\n";
+
+ // Parse the module.
+ LLVMContext Context;
+ std::unique_ptr<Module> M = makeLLVMModule(Context, ModuleString);
+
+ runWithDomTree(
+ *M, "f",
+ [&](Function &F, DominatorTree *DT, DominatorTreeBase<BasicBlock> *PDT) {
+ Function::iterator FI = F.begin();
+
+ BasicBlock *BB0 = &*FI++;
+ BasicBlock *BB1 = &*FI++;
+ BasicBlock *BB2 = &*FI++;
+
+ const TerminatorInst *TI = BB0->getTerminator();
+ assert(TI->getNumSuccessors() == 3 && "Switch has three successors");
+
+ BasicBlockEdge Edge_BB0_BB2(BB0, TI->getSuccessor(0));
+ assert(Edge_BB0_BB2.getEnd() == BB2 &&
+ "Default label is the 1st successor");
+
+ BasicBlockEdge Edge_BB0_BB1_a(BB0, TI->getSuccessor(1));
+ assert(Edge_BB0_BB1_a.getEnd() == BB1 && "BB1 is the 2nd successor");
+
+ BasicBlockEdge Edge_BB0_BB1_b(BB0, TI->getSuccessor(2));
+ assert(Edge_BB0_BB1_b.getEnd() == BB1 && "BB1 is the 3rd successor");
+
+ EXPECT_TRUE(DT->dominates(Edge_BB0_BB2, BB2));
+ EXPECT_FALSE(DT->dominates(Edge_BB0_BB2, BB1));
+
+ EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_a, BB1));
+ EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_b, BB1));
+
+ EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_a, BB2));
+ EXPECT_FALSE(DT->dominates(Edge_BB0_BB1_b, BB2));
+ });
+}
diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp
index 5686c3b2b3a7..186330f10573 100644
--- a/unittests/IR/IRBuilderTest.cpp
+++ b/unittests/IR/IRBuilderTest.cpp
@@ -9,8 +9,8 @@
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp
index 9f8fc4eaeb6f..bcf3babf7f68 100644
--- a/unittests/IR/MetadataTest.cpp
+++ b/unittests/IR/MetadataTest.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/Metadata.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
@@ -14,7 +15,6 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Type.h"
diff --git a/unittests/IR/ModuleTest.cpp b/unittests/IR/ModuleTest.cpp
index 9f52fedc4559..d93d036bb115 100644
--- a/unittests/IR/ModuleTest.cpp
+++ b/unittests/IR/ModuleTest.cpp
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/GlobalVariable.h"
#include "llvm/Support/RandomNumberGenerator.h"
#include "gtest/gtest.h"
diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp
index b3a039a364fc..ad06cc4778fe 100644
--- a/unittests/IR/PassManagerTest.cpp
+++ b/unittests/IR/PassManagerTest.cpp
@@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/PassManager.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/PassManager.h"
#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"
diff --git a/unittests/IR/PatternMatch.cpp b/unittests/IR/PatternMatch.cpp
index 2d1321def7e3..02ef87f5b13e 100644
--- a/unittests/IR/PatternMatch.cpp
+++ b/unittests/IR/PatternMatch.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/PatternMatch.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
@@ -21,7 +22,6 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/NoFolder.h"
#include "llvm/IR/Operator.h"
-#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Type.h"
#include "gtest/gtest.h"
diff --git a/unittests/IR/UserTest.cpp b/unittests/IR/UserTest.cpp
index 7ba6840313b1..794dfc133bba 100644
--- a/unittests/IR/UserTest.cpp
+++ b/unittests/IR/UserTest.cpp
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/User.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/User.h"
#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"
using namespace llvm;
diff --git a/unittests/IR/ValueTest.cpp b/unittests/IR/ValueTest.cpp
index 142444a809c6..0087cb2fa82c 100644
--- a/unittests/IR/ValueTest.cpp
+++ b/unittests/IR/ValueTest.cpp
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/Value.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
-#include "llvm/IR/Value.h"
#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"
using namespace llvm;
diff --git a/unittests/IR/VerifierTest.cpp b/unittests/IR/VerifierTest.cpp
index 188509aadf77..f1f453ed5d10 100644
--- a/unittests/IR/VerifierTest.cpp
+++ b/unittests/IR/VerifierTest.cpp
@@ -7,18 +7,18 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/Verifier.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalVariable.h"
-#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
-#include "llvm/IR/Verifier.h"
#include "gtest/gtest.h"
namespace llvm {