[llvm-commits] [llvm] r67652 - in /llvm/trunk: test/Integer/a1.ll test/Integer/a1.ll.out unittests/ADT/APIntTest.cpp unittests/Makefile unittests/VMCore/ unittests/VMCore/ConstantsTest.cpp unittests/VMCore/Makefile

Misha Brukman brukman+llvm at gmail.com
Tue Mar 24 14:36:09 PDT 2009


Author: brukman
Date: Tue Mar 24 16:36:09 2009
New Revision: 67652

URL: http://llvm.org/viewvc/llvm-project?rev=67652&view=rev
Log:
Converted a1.ll to unittests.

Added:
    llvm/trunk/unittests/VMCore/
    llvm/trunk/unittests/VMCore/ConstantsTest.cpp
    llvm/trunk/unittests/VMCore/Makefile
Removed:
    llvm/trunk/test/Integer/a1.ll
    llvm/trunk/test/Integer/a1.ll.out
Modified:
    llvm/trunk/unittests/ADT/APIntTest.cpp
    llvm/trunk/unittests/Makefile

Removed: llvm/trunk/test/Integer/a1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Integer/a1.ll?rev=67651&view=auto

==============================================================================
--- llvm/trunk/test/Integer/a1.ll (original)
+++ llvm/trunk/test/Integer/a1.ll (removed)
@@ -1,25 +0,0 @@
-; RUN: llvm-as %s -o - | llvm-dis > %t.ll
-; RUN: diff %t.ll %s.out
-
-; test 1 bit
-;
- at b = constant i1 add(i1 1 , i1 1)
- at c = constant i1 add(i1 -1, i1 1)
- at d = constant i1 add(i1 -1, i1 -1)
- at e = constant i1 sub(i1 -1, i1 1)
- at f = constant i1 sub(i1 1 , i1 -1)
- at g = constant i1 sub(i1 1 , i1 1)
-
- at h = constant i1 shl(i1 1 , i1 1)  ; undefined
- at i = constant i1 shl(i1 1 , i1 0)
- at j = constant i1 lshr(i1 1, i1 1)  ; undefined
- at m = constant i1 ashr(i1 1, i1 1)  ; undefined
-
- at n = constant i1 mul(i1 -1, i1 1)
- at o = constant i1 sdiv(i1 -1, i1 1) ; overflow
- at p = constant i1 sdiv(i1 1 , i1 -1); overflow
- at q = constant i1 udiv(i1 -1, i1 1)
- at r = constant i1 udiv(i1 1, i1 -1)
- at s = constant i1 srem(i1 -1, i1 1) ; overflow
- at t = constant i1 urem(i1 -1, i1 1)
- at u = constant i1 srem(i1  1, i1 -1) ; overflow

Removed: llvm/trunk/test/Integer/a1.ll.out
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Integer/a1.ll.out?rev=67651&view=auto

==============================================================================
--- llvm/trunk/test/Integer/a1.ll.out (original)
+++ llvm/trunk/test/Integer/a1.ll.out (removed)
@@ -1,19 +0,0 @@
-; ModuleID = '<stdin>'
- at b = constant i1 false		; <i1*> [#uses=0]
- at c = constant i1 false		; <i1*> [#uses=0]
- at d = constant i1 false		; <i1*> [#uses=0]
- at e = constant i1 false		; <i1*> [#uses=0]
- at f = constant i1 false		; <i1*> [#uses=0]
- at g = constant i1 false		; <i1*> [#uses=0]
- at h = constant i1 undef		; <i1*> [#uses=0]
- at i = constant i1 true		; <i1*> [#uses=0]
- at j = constant i1 undef		; <i1*> [#uses=0]
- at m = constant i1 undef		; <i1*> [#uses=0]
- at n = constant i1 true		; <i1*> [#uses=0]
- at o = constant i1 true		; <i1*> [#uses=0]
- at p = constant i1 true		; <i1*> [#uses=0]
- at q = constant i1 true		; <i1*> [#uses=0]
- at r = constant i1 true		; <i1*> [#uses=0]
- at s = constant i1 false		; <i1*> [#uses=0]
- at t = constant i1 false		; <i1*> [#uses=0]
- at u = constant i1 false		; <i1*> [#uses=0]

Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=67652&r1=67651&r2=67652&view=diff

==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Tue Mar 24 16:36:09 2009
@@ -7,13 +7,29 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <ostream>
+#include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/SmallString.h"
 
 using namespace llvm;
 
 namespace {
 
+// Make the Google Test failure output equivalent to APInt::dump()
+std::ostream& operator<<(std::ostream &OS, const llvm::APInt& I) {
+  llvm::raw_os_ostream raw_os(OS);
+
+  SmallString<40> S, U;
+  I.toStringUnsigned(U);
+  I.toStringSigned(S);
+  raw_os << "APInt(" << I.getBitWidth()<< "b, "
+         << U.c_str() << "u " << S.c_str() << "s)";
+  raw_os.flush();
+  return OS;
+}
+
 // Test that APInt shift left works when bitwidth > 64 and shiftamt == 0
 TEST(APIntTest, ShiftLeftByZero) {
   APInt One = APInt::getNullValue(65) + 1;
@@ -22,7 +38,7 @@
   EXPECT_EQ(false, Shl[1]);
 }
 
-TEST(APIntTest, I128NegativeCount) {
+TEST(APIntTest, i128_NegativeCount) {
   APInt Minus3(128, (uint64_t)-3, true);
   EXPECT_EQ(126u, Minus3.countLeadingOnes());
   EXPECT_EQ(-3, Minus3.getSExtValue());
@@ -37,7 +53,7 @@
   EXPECT_EQ(-1, Minus1.getSExtValue());
 }
 
-TEST(APIntTest, I33Count) {
+TEST(APIntTest, i33_Count) {
   APInt i33minus2(33, -2, true);
   EXPECT_EQ(0u, i33minus2.countLeadingZeros());
   EXPECT_EQ(32u, i33minus2.countLeadingOnes());
@@ -48,7 +64,7 @@
   EXPECT_EQ(((uint64_t)-2)&((1ull<<33) -1), i33minus2.getZExtValue());
 }
 
-TEST(APIntTest, I65Count) {
+TEST(APIntTest, i65_Count) {
   APInt i65minus(65, 0, true);
   i65minus.set(64);
   EXPECT_EQ(0u, i65minus.countLeadingZeros());
@@ -58,7 +74,7 @@
   EXPECT_EQ(1u, i65minus.countPopulation());
 }
 
-TEST(APIntTest, I128PositiveCount) {
+TEST(APIntTest, i128_PositiveCount) {
   APInt u128max = APInt::getAllOnesValue(128);
   EXPECT_EQ(128u, u128max.countLeadingOnes());
   EXPECT_EQ(0u, u128max.countLeadingZeros());
@@ -97,4 +113,67 @@
   EXPECT_EQ(1u, one.getZExtValue());
 }
 
+TEST(APIntTest, i1) {
+  const APInt neg_two(1, -2, true);
+  const APInt neg_one(1, -1, true);
+  const APInt zero(1, 0);
+  const APInt one(1, 1);
+  const APInt two(1, 2);
+
+  EXPECT_EQ(0, neg_two.getSExtValue());
+  EXPECT_EQ(-1, neg_one.getSExtValue());
+  EXPECT_EQ(1u, neg_one.getZExtValue());
+  EXPECT_EQ(0u, zero.getZExtValue());
+  EXPECT_EQ(-1, one.getSExtValue());
+  EXPECT_EQ(1u, one.getZExtValue());
+  EXPECT_EQ(0u, two.getZExtValue());
+  EXPECT_EQ(0, two.getSExtValue());
+
+  // Basic equalities for 1-bit values.
+  EXPECT_EQ(zero, two);
+  EXPECT_EQ(zero, neg_two);
+  EXPECT_EQ(one, neg_one);
+  EXPECT_EQ(two, neg_two);
+
+  // Additions.
+  EXPECT_EQ(two, one + one);
+  EXPECT_EQ(zero, neg_one + one);
+  EXPECT_EQ(neg_two, neg_one + neg_one);
+
+  // Subtractions.
+  EXPECT_EQ(neg_two, neg_one - one);
+  EXPECT_EQ(two, one - neg_one);
+  EXPECT_EQ(zero, one - one);
+
+  // Shifts.
+  EXPECT_EQ(zero, one << one);
+  EXPECT_EQ(one, one << zero);
+  EXPECT_EQ(zero, one.shl(1));
+  EXPECT_EQ(one, one.shl(0));
+  EXPECT_EQ(zero, one.lshr(1));
+  EXPECT_EQ(zero, one.ashr(1));
+
+  // Multiplies.
+  EXPECT_EQ(neg_one, neg_one * one);
+  EXPECT_EQ(neg_one, one * neg_one);
+  EXPECT_EQ(one, neg_one * neg_one);
+  EXPECT_EQ(one, one * one);
+
+  // Divides.
+  EXPECT_EQ(neg_one, one.sdiv(neg_one));
+  EXPECT_EQ(neg_one, neg_one.sdiv(one));
+  EXPECT_EQ(one, neg_one.sdiv(neg_one));
+  EXPECT_EQ(one, one.sdiv(one));
+
+  EXPECT_EQ(neg_one, one.udiv(neg_one));
+  EXPECT_EQ(neg_one, neg_one.udiv(one));
+  EXPECT_EQ(one, neg_one.udiv(neg_one));
+  EXPECT_EQ(one, one.udiv(one));
+
+  // Remainders.
+  EXPECT_EQ(zero, neg_one.srem(one));
+  EXPECT_EQ(zero, neg_one.urem(one));
+  EXPECT_EQ(zero, one.srem(neg_one));
+}
+
 }

Modified: llvm/trunk/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Makefile?rev=67652&r1=67651&r2=67652&view=diff

==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Makefile Tue Mar 24 16:36:09 2009
@@ -16,7 +16,7 @@
 CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
 CPP.Flags += -Wno-variadic-macros
 
-PARALLEL_DIRS = ADT Support
+PARALLEL_DIRS = ADT Support VMCore
 
 include $(LEVEL)/Makefile.common
 

Added: llvm/trunk/unittests/VMCore/ConstantsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/ConstantsTest.cpp?rev=67652&view=auto

==============================================================================
--- llvm/trunk/unittests/VMCore/ConstantsTest.cpp (added)
+++ llvm/trunk/unittests/VMCore/ConstantsTest.cpp Tue Mar 24 16:36:09 2009
@@ -0,0 +1,98 @@
+//===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants unit tests ------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+TEST(ConstantsTest, Integer_i1) {
+  const IntegerType* Int1 = IntegerType::get(1);
+  Constant* One = ConstantInt::get(Int1, 1, true);
+  Constant* Zero = ConstantInt::get(Int1, 0);
+  Constant* NegOne = ConstantInt::get(Int1, -1, true);
+  Constant* Undef = UndefValue::get(Int1);
+
+  // Input:  @b = constant i1 add(i1 1 , i1 1)
+  // Output: @b = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One));
+
+  // @c = constant i1 add(i1 -1, i1 1)
+  // @c = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One));
+
+  // @d = constant i1 add(i1 -1, i1 -1)
+  // @d = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne));
+
+  // @e = constant i1 sub(i1 -1, i1 1)
+  // @e = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One));
+
+  // @f = constant i1 sub(i1 1 , i1 -1)
+  // @f = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne));
+
+  // @g = constant i1 sub(i1 1 , i1 1)
+  // @g = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getSub(One, One));
+
+  // @h = constant i1 shl(i1 1 , i1 1)  ; undefined
+  // @h = constant i1 undef
+  EXPECT_EQ(Undef, ConstantExpr::getShl(One, One));
+
+  // @i = constant i1 shl(i1 1 , i1 0)
+  // @i = constant i1 true
+  EXPECT_EQ(One, ConstantExpr::getShl(One, Zero));
+
+  // @j = constant i1 lshr(i1 1, i1 1)  ; undefined
+  // @j = constant i1 undef
+  EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One));
+
+  // @m = constant i1 ashr(i1 1, i1 1)  ; undefined
+  // @m = constant i1 undef
+  EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One));
+
+  // @n = constant i1 mul(i1 -1, i1 1)
+  // @n = constant i1 true
+  EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One));
+
+  // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow
+  // @o = constant i1 true
+  EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One));
+
+  // @p = constant i1 sdiv(i1 1 , i1 -1); overflow
+  // @p = constant i1 true
+  EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne));
+
+  // @q = constant i1 udiv(i1 -1, i1 1)
+  // @q = constant i1 true
+  EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One));
+
+  // @r = constant i1 udiv(i1 1, i1 -1)
+  // @r = constant i1 true
+  EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne));
+
+  // @s = constant i1 srem(i1 -1, i1 1) ; overflow
+  // @s = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One));
+
+  // @t = constant i1 urem(i1 -1, i1 1)
+  // @t = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One));
+
+  // @u = constant i1 srem(i1  1, i1 -1) ; overflow
+  // @u = constant i1 false
+  EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne));
+}
+
+}  // end anonymous namespace
+}  // end namespace llvm

Added: llvm/trunk/unittests/VMCore/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/Makefile?rev=67652&view=auto

==============================================================================
--- llvm/trunk/unittests/VMCore/Makefile (added)
+++ llvm/trunk/unittests/VMCore/Makefile Tue Mar 24 16:36:09 2009
@@ -0,0 +1,15 @@
+##===- unittests/VMCore/Makefile ---------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+TESTNAME = VMCore
+LINK_COMPONENTS := core support
+
+include $(LEVEL)/Makefile.config
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest





More information about the llvm-commits mailing list