Misha Brukman | d1d2c50 | 2009-03-24 21:36:09 +0000 | [diff] [blame^] | 1 | //===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants unit tests ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/Constants.h" |
| 11 | #include "llvm/DerivedTypes.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | namespace llvm { |
| 15 | namespace { |
| 16 | |
| 17 | TEST(ConstantsTest, Integer_i1) { |
| 18 | const IntegerType* Int1 = IntegerType::get(1); |
| 19 | Constant* One = ConstantInt::get(Int1, 1, true); |
| 20 | Constant* Zero = ConstantInt::get(Int1, 0); |
| 21 | Constant* NegOne = ConstantInt::get(Int1, -1, true); |
| 22 | Constant* Undef = UndefValue::get(Int1); |
| 23 | |
| 24 | // Input: @b = constant i1 add(i1 1 , i1 1) |
| 25 | // Output: @b = constant i1 false |
| 26 | EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One)); |
| 27 | |
| 28 | // @c = constant i1 add(i1 -1, i1 1) |
| 29 | // @c = constant i1 false |
| 30 | EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One)); |
| 31 | |
| 32 | // @d = constant i1 add(i1 -1, i1 -1) |
| 33 | // @d = constant i1 false |
| 34 | EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne)); |
| 35 | |
| 36 | // @e = constant i1 sub(i1 -1, i1 1) |
| 37 | // @e = constant i1 false |
| 38 | EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One)); |
| 39 | |
| 40 | // @f = constant i1 sub(i1 1 , i1 -1) |
| 41 | // @f = constant i1 false |
| 42 | EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne)); |
| 43 | |
| 44 | // @g = constant i1 sub(i1 1 , i1 1) |
| 45 | // @g = constant i1 false |
| 46 | EXPECT_EQ(Zero, ConstantExpr::getSub(One, One)); |
| 47 | |
| 48 | // @h = constant i1 shl(i1 1 , i1 1) ; undefined |
| 49 | // @h = constant i1 undef |
| 50 | EXPECT_EQ(Undef, ConstantExpr::getShl(One, One)); |
| 51 | |
| 52 | // @i = constant i1 shl(i1 1 , i1 0) |
| 53 | // @i = constant i1 true |
| 54 | EXPECT_EQ(One, ConstantExpr::getShl(One, Zero)); |
| 55 | |
| 56 | // @j = constant i1 lshr(i1 1, i1 1) ; undefined |
| 57 | // @j = constant i1 undef |
| 58 | EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One)); |
| 59 | |
| 60 | // @m = constant i1 ashr(i1 1, i1 1) ; undefined |
| 61 | // @m = constant i1 undef |
| 62 | EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One)); |
| 63 | |
| 64 | // @n = constant i1 mul(i1 -1, i1 1) |
| 65 | // @n = constant i1 true |
| 66 | EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One)); |
| 67 | |
| 68 | // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow |
| 69 | // @o = constant i1 true |
| 70 | EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One)); |
| 71 | |
| 72 | // @p = constant i1 sdiv(i1 1 , i1 -1); overflow |
| 73 | // @p = constant i1 true |
| 74 | EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne)); |
| 75 | |
| 76 | // @q = constant i1 udiv(i1 -1, i1 1) |
| 77 | // @q = constant i1 true |
| 78 | EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One)); |
| 79 | |
| 80 | // @r = constant i1 udiv(i1 1, i1 -1) |
| 81 | // @r = constant i1 true |
| 82 | EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne)); |
| 83 | |
| 84 | // @s = constant i1 srem(i1 -1, i1 1) ; overflow |
| 85 | // @s = constant i1 false |
| 86 | EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One)); |
| 87 | |
| 88 | // @t = constant i1 urem(i1 -1, i1 1) |
| 89 | // @t = constant i1 false |
| 90 | EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One)); |
| 91 | |
| 92 | // @u = constant i1 srem(i1 1, i1 -1) ; overflow |
| 93 | // @u = constant i1 false |
| 94 | EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne)); |
| 95 | } |
| 96 | |
| 97 | } // end anonymous namespace |
| 98 | } // end namespace llvm |