llvm.org GIT mirror llvm / 4dd6824
New unit test for the cloning module, which so far only covers cloning of instructions' optimization flags. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82934 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 10 years ago
4 changed file(s) with 120 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
88
99 LEVEL = ..
1010
11 PARALLEL_DIRS = ADT ExecutionEngine Support VMCore
11 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore
1212
1313 include $(LEVEL)/Makefile.common
1414
0 ##===- unittests/Transforms/Makefile -----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10
11 PARALLEL_DIRS = Utils
12
13 include $(LEVEL)/Makefile.common
14
15 clean::
16 $(Verb) $(RM) -f *Tests
0 //===- Cloning.cpp - Unit tests for the Cloner ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10 #include "llvm/Argument.h"
11 #include "llvm/Instructions.h"
12
13 using namespace llvm;
14
15 TEST(CloneInstruction, OverflowBits) {
16 LLVMContext context;
17 Value *V = new Argument(Type::getInt32Ty(context));
18
19 BinaryOperator *Add = BinaryOperator::Create(Instruction::Add, V, V);
20 BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
21 BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
22
23 EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap());
24 EXPECT_FALSE(Add->clone()->hasNoSignedWrap());
25 EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap());
26 EXPECT_FALSE(Sub->clone()->hasNoSignedWrap());
27 EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap());
28 EXPECT_FALSE(Mul->clone()->hasNoSignedWrap());
29
30 Add->setHasNoUnsignedWrap();
31 Sub->setHasNoUnsignedWrap();
32 Mul->setHasNoUnsignedWrap();
33
34 EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap());
35 EXPECT_FALSE(Add->clone()->hasNoSignedWrap());
36 EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap());
37 EXPECT_FALSE(Sub->clone()->hasNoSignedWrap());
38 EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap());
39 EXPECT_FALSE(Mul->clone()->hasNoSignedWrap());
40
41 Add->setHasNoSignedWrap();
42 Sub->setHasNoSignedWrap();
43 Mul->setHasNoSignedWrap();
44
45 EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap());
46 EXPECT_TRUE(Add->clone()->hasNoSignedWrap());
47 EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap());
48 EXPECT_TRUE(Sub->clone()->hasNoSignedWrap());
49 EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap());
50 EXPECT_TRUE(Mul->clone()->hasNoSignedWrap());
51
52 Add->setHasNoUnsignedWrap(false);
53 Sub->setHasNoUnsignedWrap(false);
54 Mul->setHasNoUnsignedWrap(false);
55
56 EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap());
57 EXPECT_TRUE(Add->clone()->hasNoSignedWrap());
58 EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap());
59 EXPECT_TRUE(Sub->clone()->hasNoSignedWrap());
60 EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap());
61 EXPECT_TRUE(Mul->clone()->hasNoSignedWrap());
62 }
63
64 TEST(CloneInstruction, Inbounds) {
65 LLVMContext context;
66 Value *V = new Argument(Type::getInt32Ty(context)->getPointerTo());
67 Constant *Z = Constant::getNullValue(Type::getInt32Ty(context));
68 std::vector ops;
69 ops.push_back(Z);
70 GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
71 EXPECT_FALSE(GEP->clone()->isInBounds());
72
73 GEP->setIsInBounds();
74 EXPECT_TRUE(GEP->clone()->isInBounds());
75 }
76
77 TEST(CloneInstruction, Exact) {
78 LLVMContext context;
79 Value *V = new Argument(Type::getInt32Ty(context));
80
81 BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
82 EXPECT_FALSE(SDiv->clone()->isExact());
83
84 SDiv->setIsExact(true);
85 EXPECT_TRUE(SDiv->clone()->isExact());
86 }
0 ##===- unittests/Transforms/Utils/Makefile -----------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 TESTNAME = Utils
11 LINK_COMPONENTS := core support transformutils
12
13 include $(LEVEL)/Makefile.config
14 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest