llvm.org GIT mirror llvm / 2e73426
Converted a1.ll to unittests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67652 91177308-0d34-0410-b5e6-96231b3b80d8 Misha Brukman 10 years ago
6 changed file(s) with 197 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
+0
-25
test/Integer/a1.ll less more
None ; RUN: llvm-as %s -o - | llvm-dis > %t.ll
1 ; RUN: diff %t.ll %s.out
2
3 ; test 1 bit
4 ;
5 @b = constant i1 add(i1 1 , i1 1)
6 @c = constant i1 add(i1 -1, i1 1)
7 @d = constant i1 add(i1 -1, i1 -1)
8 @e = constant i1 sub(i1 -1, i1 1)
9 @f = constant i1 sub(i1 1 , i1 -1)
10 @g = constant i1 sub(i1 1 , i1 1)
11
12 @h = constant i1 shl(i1 1 , i1 1) ; undefined
13 @i = constant i1 shl(i1 1 , i1 0)
14 @j = constant i1 lshr(i1 1, i1 1) ; undefined
15 @m = constant i1 ashr(i1 1, i1 1) ; undefined
16
17 @n = constant i1 mul(i1 -1, i1 1)
18 @o = constant i1 sdiv(i1 -1, i1 1) ; overflow
19 @p = constant i1 sdiv(i1 1 , i1 -1); overflow
20 @q = constant i1 udiv(i1 -1, i1 1)
21 @r = constant i1 udiv(i1 1, i1 -1)
22 @s = constant i1 srem(i1 -1, i1 1) ; overflow
23 @t = constant i1 urem(i1 -1, i1 1)
24 @u = constant i1 srem(i1 1, i1 -1) ; overflow
+0
-19
test/Integer/a1.ll.out less more
None ; ModuleID = ''
1 @b = constant i1 false ; [#uses=0]
2 @c = constant i1 false ; [#uses=0]
3 @d = constant i1 false ; [#uses=0]
4 @e = constant i1 false ; [#uses=0]
5 @f = constant i1 false ; [#uses=0]
6 @g = constant i1 false ; [#uses=0]
7 @h = constant i1 undef ; [#uses=0]
8 @i = constant i1 true ; [#uses=0]
9 @j = constant i1 undef ; [#uses=0]
10 @m = constant i1 undef ; [#uses=0]
11 @n = constant i1 true ; [#uses=0]
12 @o = constant i1 true ; [#uses=0]
13 @p = constant i1 true ; [#uses=0]
14 @q = constant i1 true ; [#uses=0]
15 @r = constant i1 true ; [#uses=0]
16 @s = constant i1 false ; [#uses=0]
17 @t = constant i1 false ; [#uses=0]
18 @u = constant i1 false ; [#uses=0]
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include
10 #include "llvm/Support/raw_ostream.h"
911 #include "gtest/gtest.h"
1012 #include "llvm/ADT/APInt.h"
13 #include "llvm/ADT/SmallString.h"
1114
1215 using namespace llvm;
1316
1417 namespace {
18
19 // Make the Google Test failure output equivalent to APInt::dump()
20 std::ostream& operator<<(std::ostream &OS, const llvm::APInt& I) {
21 llvm::raw_os_ostream raw_os(OS);
22
23 SmallString<40> S, U;
24 I.toStringUnsigned(U);
25 I.toStringSigned(S);
26 raw_os << "APInt(" << I.getBitWidth()<< "b, "
27 << U.c_str() << "u " << S.c_str() << "s)";
28 raw_os.flush();
29 return OS;
30 }
1531
1632 // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0
1733 TEST(APIntTest, ShiftLeftByZero) {
2137 EXPECT_EQ(false, Shl[1]);
2238 }
2339
24 TEST(APIntTest, I128NegativeCount) {
40 TEST(APIntTest, i128_NegativeCount) {
2541 APInt Minus3(128, (uint64_t)-3, true);
2642 EXPECT_EQ(126u, Minus3.countLeadingOnes());
2743 EXPECT_EQ(-3, Minus3.getSExtValue());
3652 EXPECT_EQ(-1, Minus1.getSExtValue());
3753 }
3854
39 TEST(APIntTest, I33Count) {
55 TEST(APIntTest, i33_Count) {
4056 APInt i33minus2(33, -2, true);
4157 EXPECT_EQ(0u, i33minus2.countLeadingZeros());
4258 EXPECT_EQ(32u, i33minus2.countLeadingOnes());
4763 EXPECT_EQ(((uint64_t)-2)&((1ull<<33) -1), i33minus2.getZExtValue());
4864 }
4965
50 TEST(APIntTest, I65Count) {
66 TEST(APIntTest, i65_Count) {
5167 APInt i65minus(65, 0, true);
5268 i65minus.set(64);
5369 EXPECT_EQ(0u, i65minus.countLeadingZeros());
5773 EXPECT_EQ(1u, i65minus.countPopulation());
5874 }
5975
60 TEST(APIntTest, I128PositiveCount) {
76 TEST(APIntTest, i128_PositiveCount) {
6177 APInt u128max = APInt::getAllOnesValue(128);
6278 EXPECT_EQ(128u, u128max.countLeadingOnes());
6379 EXPECT_EQ(0u, u128max.countLeadingZeros());
96112 EXPECT_EQ(1u, one.getZExtValue());
97113 }
98114
115 TEST(APIntTest, i1) {
116 const APInt neg_two(1, -2, true);
117 const APInt neg_one(1, -1, true);
118 const APInt zero(1, 0);
119 const APInt one(1, 1);
120 const APInt two(1, 2);
121
122 EXPECT_EQ(0, neg_two.getSExtValue());
123 EXPECT_EQ(-1, neg_one.getSExtValue());
124 EXPECT_EQ(1u, neg_one.getZExtValue());
125 EXPECT_EQ(0u, zero.getZExtValue());
126 EXPECT_EQ(-1, one.getSExtValue());
127 EXPECT_EQ(1u, one.getZExtValue());
128 EXPECT_EQ(0u, two.getZExtValue());
129 EXPECT_EQ(0, two.getSExtValue());
130
131 // Basic equalities for 1-bit values.
132 EXPECT_EQ(zero, two);
133 EXPECT_EQ(zero, neg_two);
134 EXPECT_EQ(one, neg_one);
135 EXPECT_EQ(two, neg_two);
136
137 // Additions.
138 EXPECT_EQ(two, one + one);
139 EXPECT_EQ(zero, neg_one + one);
140 EXPECT_EQ(neg_two, neg_one + neg_one);
141
142 // Subtractions.
143 EXPECT_EQ(neg_two, neg_one - one);
144 EXPECT_EQ(two, one - neg_one);
145 EXPECT_EQ(zero, one - one);
146
147 // Shifts.
148 EXPECT_EQ(zero, one << one);
149 EXPECT_EQ(one, one << zero);
150 EXPECT_EQ(zero, one.shl(1));
151 EXPECT_EQ(one, one.shl(0));
152 EXPECT_EQ(zero, one.lshr(1));
153 EXPECT_EQ(zero, one.ashr(1));
154
155 // Multiplies.
156 EXPECT_EQ(neg_one, neg_one * one);
157 EXPECT_EQ(neg_one, one * neg_one);
158 EXPECT_EQ(one, neg_one * neg_one);
159 EXPECT_EQ(one, one * one);
160
161 // Divides.
162 EXPECT_EQ(neg_one, one.sdiv(neg_one));
163 EXPECT_EQ(neg_one, neg_one.sdiv(one));
164 EXPECT_EQ(one, neg_one.sdiv(neg_one));
165 EXPECT_EQ(one, one.sdiv(one));
166
167 EXPECT_EQ(neg_one, one.udiv(neg_one));
168 EXPECT_EQ(neg_one, neg_one.udiv(one));
169 EXPECT_EQ(one, neg_one.udiv(neg_one));
170 EXPECT_EQ(one, one.udiv(one));
171
172 // Remainders.
173 EXPECT_EQ(zero, neg_one.srem(one));
174 EXPECT_EQ(zero, neg_one.urem(one));
175 EXPECT_EQ(zero, one.srem(neg_one));
99176 }
177
178 }
1515 CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
1616 CPP.Flags += -Wno-variadic-macros
1717
18 PARALLEL_DIRS = ADT Support
18 PARALLEL_DIRS = ADT Support VMCore
1919
2020 include $(LEVEL)/Makefile.common
2121
0 //===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants unit tests ------===//
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 "llvm/Constants.h"
10 #include "llvm/DerivedTypes.h"
11 #include "gtest/gtest.h"
12
13 namespace llvm {
14 namespace {
15
16 TEST(ConstantsTest, Integer_i1) {
17 const IntegerType* Int1 = IntegerType::get(1);
18 Constant* One = ConstantInt::get(Int1, 1, true);
19 Constant* Zero = ConstantInt::get(Int1, 0);
20 Constant* NegOne = ConstantInt::get(Int1, -1, true);
21 Constant* Undef = UndefValue::get(Int1);
22
23 // Input: @b = constant i1 add(i1 1 , i1 1)
24 // Output: @b = constant i1 false
25 EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One));
26
27 // @c = constant i1 add(i1 -1, i1 1)
28 // @c = constant i1 false
29 EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One));
30
31 // @d = constant i1 add(i1 -1, i1 -1)
32 // @d = constant i1 false
33 EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne));
34
35 // @e = constant i1 sub(i1 -1, i1 1)
36 // @e = constant i1 false
37 EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One));
38
39 // @f = constant i1 sub(i1 1 , i1 -1)
40 // @f = constant i1 false
41 EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne));
42
43 // @g = constant i1 sub(i1 1 , i1 1)
44 // @g = constant i1 false
45 EXPECT_EQ(Zero, ConstantExpr::getSub(One, One));
46
47 // @h = constant i1 shl(i1 1 , i1 1) ; undefined
48 // @h = constant i1 undef
49 EXPECT_EQ(Undef, ConstantExpr::getShl(One, One));
50
51 // @i = constant i1 shl(i1 1 , i1 0)
52 // @i = constant i1 true
53 EXPECT_EQ(One, ConstantExpr::getShl(One, Zero));
54
55 // @j = constant i1 lshr(i1 1, i1 1) ; undefined
56 // @j = constant i1 undef
57 EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One));
58
59 // @m = constant i1 ashr(i1 1, i1 1) ; undefined
60 // @m = constant i1 undef
61 EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One));
62
63 // @n = constant i1 mul(i1 -1, i1 1)
64 // @n = constant i1 true
65 EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One));
66
67 // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow
68 // @o = constant i1 true
69 EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One));
70
71 // @p = constant i1 sdiv(i1 1 , i1 -1); overflow
72 // @p = constant i1 true
73 EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne));
74
75 // @q = constant i1 udiv(i1 -1, i1 1)
76 // @q = constant i1 true
77 EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One));
78
79 // @r = constant i1 udiv(i1 1, i1 -1)
80 // @r = constant i1 true
81 EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne));
82
83 // @s = constant i1 srem(i1 -1, i1 1) ; overflow
84 // @s = constant i1 false
85 EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One));
86
87 // @t = constant i1 urem(i1 -1, i1 1)
88 // @t = constant i1 false
89 EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One));
90
91 // @u = constant i1 srem(i1 1, i1 -1) ; overflow
92 // @u = constant i1 false
93 EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne));
94 }
95
96 } // end anonymous namespace
97 } // end namespace llvm
0 ##===- unittests/VMCore/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 = VMCore
11 LINK_COMPONENTS := core support
12
13 include $(LEVEL)/Makefile.config
14 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest