2014-03-04 20:24:34 +08:00
|
|
|
//===- ConstantRangeTest.cpp - ConstantRange tests ------------------------===//
|
2009-07-10 06:07:27 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-04 20:24:34 +08:00
|
|
|
#include "llvm/IR/ConstantRange.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2015-10-22 11:12:57 +08:00
|
|
|
#include "llvm/IR/Operator.h"
|
2009-07-10 06:07:27 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
class ConstantRangeTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
static ConstantRange Full;
|
|
|
|
static ConstantRange Empty;
|
|
|
|
static ConstantRange One;
|
|
|
|
static ConstantRange Some;
|
|
|
|
static ConstantRange Wrap;
|
|
|
|
};
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
ConstantRange ConstantRangeTest::Full(16);
|
|
|
|
ConstantRange ConstantRangeTest::Empty(16, false);
|
|
|
|
ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
|
|
|
|
ConstantRange ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa));
|
|
|
|
ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
|
|
|
|
|
|
|
|
TEST_F(ConstantRangeTest, Basics) {
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_TRUE(Full.isFullSet());
|
|
|
|
EXPECT_FALSE(Full.isEmptySet());
|
2010-08-07 13:47:46 +08:00
|
|
|
EXPECT_TRUE(Full.inverse().isEmptySet());
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_FALSE(Full.isWrappedSet());
|
|
|
|
EXPECT_TRUE(Full.contains(APInt(16, 0x0)));
|
|
|
|
EXPECT_TRUE(Full.contains(APInt(16, 0x9)));
|
|
|
|
EXPECT_TRUE(Full.contains(APInt(16, 0xa)));
|
|
|
|
EXPECT_TRUE(Full.contains(APInt(16, 0xaa9)));
|
|
|
|
EXPECT_TRUE(Full.contains(APInt(16, 0xaaa)));
|
|
|
|
|
|
|
|
EXPECT_FALSE(Empty.isFullSet());
|
|
|
|
EXPECT_TRUE(Empty.isEmptySet());
|
2010-08-07 13:47:46 +08:00
|
|
|
EXPECT_TRUE(Empty.inverse().isFullSet());
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_FALSE(Empty.isWrappedSet());
|
|
|
|
EXPECT_FALSE(Empty.contains(APInt(16, 0x0)));
|
|
|
|
EXPECT_FALSE(Empty.contains(APInt(16, 0x9)));
|
|
|
|
EXPECT_FALSE(Empty.contains(APInt(16, 0xa)));
|
|
|
|
EXPECT_FALSE(Empty.contains(APInt(16, 0xaa9)));
|
|
|
|
EXPECT_FALSE(Empty.contains(APInt(16, 0xaaa)));
|
|
|
|
|
|
|
|
EXPECT_FALSE(One.isFullSet());
|
|
|
|
EXPECT_FALSE(One.isEmptySet());
|
|
|
|
EXPECT_FALSE(One.isWrappedSet());
|
|
|
|
EXPECT_FALSE(One.contains(APInt(16, 0x0)));
|
|
|
|
EXPECT_FALSE(One.contains(APInt(16, 0x9)));
|
|
|
|
EXPECT_TRUE(One.contains(APInt(16, 0xa)));
|
|
|
|
EXPECT_FALSE(One.contains(APInt(16, 0xaa9)));
|
|
|
|
EXPECT_FALSE(One.contains(APInt(16, 0xaaa)));
|
2010-08-07 13:47:46 +08:00
|
|
|
EXPECT_FALSE(One.inverse().contains(APInt(16, 0xa)));
|
2009-07-10 06:07:27 +08:00
|
|
|
|
|
|
|
EXPECT_FALSE(Some.isFullSet());
|
|
|
|
EXPECT_FALSE(Some.isEmptySet());
|
|
|
|
EXPECT_FALSE(Some.isWrappedSet());
|
|
|
|
EXPECT_FALSE(Some.contains(APInt(16, 0x0)));
|
|
|
|
EXPECT_FALSE(Some.contains(APInt(16, 0x9)));
|
|
|
|
EXPECT_TRUE(Some.contains(APInt(16, 0xa)));
|
|
|
|
EXPECT_TRUE(Some.contains(APInt(16, 0xaa9)));
|
|
|
|
EXPECT_FALSE(Some.contains(APInt(16, 0xaaa)));
|
|
|
|
|
|
|
|
EXPECT_FALSE(Wrap.isFullSet());
|
|
|
|
EXPECT_FALSE(Wrap.isEmptySet());
|
|
|
|
EXPECT_TRUE(Wrap.isWrappedSet());
|
|
|
|
EXPECT_TRUE(Wrap.contains(APInt(16, 0x0)));
|
|
|
|
EXPECT_TRUE(Wrap.contains(APInt(16, 0x9)));
|
|
|
|
EXPECT_FALSE(Wrap.contains(APInt(16, 0xa)));
|
|
|
|
EXPECT_FALSE(Wrap.contains(APInt(16, 0xaa9)));
|
|
|
|
EXPECT_TRUE(Wrap.contains(APInt(16, 0xaaa)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, Equality) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full, Full);
|
|
|
|
EXPECT_EQ(Empty, Empty);
|
|
|
|
EXPECT_EQ(One, One);
|
|
|
|
EXPECT_EQ(Some, Some);
|
|
|
|
EXPECT_EQ(Wrap, Wrap);
|
|
|
|
EXPECT_NE(Full, Empty);
|
|
|
|
EXPECT_NE(Full, One);
|
|
|
|
EXPECT_NE(Full, Some);
|
|
|
|
EXPECT_NE(Full, Wrap);
|
|
|
|
EXPECT_NE(Empty, One);
|
|
|
|
EXPECT_NE(Empty, Some);
|
|
|
|
EXPECT_NE(Empty, Wrap);
|
|
|
|
EXPECT_NE(One, Some);
|
|
|
|
EXPECT_NE(One, Wrap);
|
|
|
|
EXPECT_NE(Some, Wrap);
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, SingleElement) {
|
2014-06-09 06:29:17 +08:00
|
|
|
EXPECT_EQ(Full.getSingleElement(), static_cast<APInt *>(nullptr));
|
|
|
|
EXPECT_EQ(Empty.getSingleElement(), static_cast<APInt *>(nullptr));
|
2016-10-03 04:59:05 +08:00
|
|
|
EXPECT_EQ(Full.getSingleMissingElement(), static_cast<APInt *>(nullptr));
|
|
|
|
EXPECT_EQ(Empty.getSingleMissingElement(), static_cast<APInt *>(nullptr));
|
|
|
|
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_EQ(*One.getSingleElement(), APInt(16, 0xa));
|
2014-06-09 06:29:17 +08:00
|
|
|
EXPECT_EQ(Some.getSingleElement(), static_cast<APInt *>(nullptr));
|
|
|
|
EXPECT_EQ(Wrap.getSingleElement(), static_cast<APInt *>(nullptr));
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2016-10-03 04:59:05 +08:00
|
|
|
EXPECT_EQ(One.getSingleMissingElement(), static_cast<APInt *>(nullptr));
|
|
|
|
EXPECT_EQ(Some.getSingleMissingElement(), static_cast<APInt *>(nullptr));
|
|
|
|
|
|
|
|
ConstantRange OneInverse = One.inverse();
|
|
|
|
EXPECT_EQ(*OneInverse.getSingleMissingElement(), *One.getSingleElement());
|
|
|
|
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_FALSE(Full.isSingleElement());
|
|
|
|
EXPECT_FALSE(Empty.isSingleElement());
|
|
|
|
EXPECT_TRUE(One.isSingleElement());
|
|
|
|
EXPECT_FALSE(Some.isSingleElement());
|
|
|
|
EXPECT_FALSE(Wrap.isSingleElement());
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, GetSetSize) {
|
2012-07-17 02:08:12 +08:00
|
|
|
EXPECT_EQ(Full.getSetSize(), APInt(17, 65536));
|
|
|
|
EXPECT_EQ(Empty.getSetSize(), APInt(17, 0));
|
|
|
|
EXPECT_EQ(One.getSetSize(), APInt(17, 1));
|
|
|
|
EXPECT_EQ(Some.getSetSize(), APInt(17, 0xaa0));
|
|
|
|
|
|
|
|
ConstantRange Wrap(APInt(4, 7), APInt(4, 3));
|
|
|
|
ConstantRange Wrap2(APInt(4, 8), APInt(4, 7));
|
|
|
|
EXPECT_EQ(Wrap.getSetSize(), APInt(5, 12));
|
|
|
|
EXPECT_EQ(Wrap2.getSetSize(), APInt(5, 15));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_EQ(Full.getUnsignedMax(), APInt(16, UINT16_MAX));
|
|
|
|
EXPECT_EQ(One.getUnsignedMax(), APInt(16, 0xa));
|
|
|
|
EXPECT_EQ(Some.getUnsignedMax(), APInt(16, 0xaa9));
|
|
|
|
EXPECT_EQ(Wrap.getUnsignedMax(), APInt(16, UINT16_MAX));
|
|
|
|
|
|
|
|
EXPECT_EQ(Full.getUnsignedMin(), APInt(16, 0));
|
|
|
|
EXPECT_EQ(One.getUnsignedMin(), APInt(16, 0xa));
|
|
|
|
EXPECT_EQ(Some.getUnsignedMin(), APInt(16, 0xa));
|
|
|
|
EXPECT_EQ(Wrap.getUnsignedMin(), APInt(16, 0));
|
|
|
|
|
|
|
|
EXPECT_EQ(Full.getSignedMax(), APInt(16, INT16_MAX));
|
|
|
|
EXPECT_EQ(One.getSignedMax(), APInt(16, 0xa));
|
|
|
|
EXPECT_EQ(Some.getSignedMax(), APInt(16, 0xaa9));
|
|
|
|
EXPECT_EQ(Wrap.getSignedMax(), APInt(16, INT16_MAX));
|
|
|
|
|
2009-07-23 00:17:36 +08:00
|
|
|
EXPECT_EQ(Full.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa));
|
|
|
|
EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa));
|
2009-07-23 00:17:36 +08:00
|
|
|
EXPECT_EQ(Wrap.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
|
2009-07-13 12:50:21 +08:00
|
|
|
|
|
|
|
// Found by Klee
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(),
|
|
|
|
APInt(4, 7));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2010-09-07 07:52:49 +08:00
|
|
|
TEST_F(ConstantRangeTest, SignWrapped) {
|
|
|
|
EXPECT_TRUE(Full.isSignWrappedSet());
|
|
|
|
EXPECT_FALSE(Empty.isSignWrappedSet());
|
|
|
|
EXPECT_FALSE(One.isSignWrappedSet());
|
|
|
|
EXPECT_FALSE(Some.isSignWrappedSet());
|
|
|
|
EXPECT_TRUE(Wrap.isSignWrappedSet());
|
|
|
|
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt(8, 127), APInt(8, 128)).isSignWrappedSet());
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(8, 127), APInt(8, 129)).isSignWrappedSet());
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt(8, 128), APInt(8, 129)).isSignWrappedSet());
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 9)).isSignWrappedSet());
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 250)).isSignWrappedSet());
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 10)).isSignWrappedSet());
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 251)).isSignWrappedSet());
|
|
|
|
}
|
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, Trunc) {
|
2009-07-10 06:07:27 +08:00
|
|
|
ConstantRange TFull = Full.truncate(10);
|
|
|
|
ConstantRange TEmpty = Empty.truncate(10);
|
|
|
|
ConstantRange TOne = One.truncate(10);
|
|
|
|
ConstantRange TSome = Some.truncate(10);
|
|
|
|
ConstantRange TWrap = Wrap.truncate(10);
|
|
|
|
EXPECT_TRUE(TFull.isFullSet());
|
|
|
|
EXPECT_TRUE(TEmpty.isEmptySet());
|
2010-12-07 16:25:19 +08:00
|
|
|
EXPECT_EQ(TOne, ConstantRange(One.getLower().trunc(10),
|
|
|
|
One.getUpper().trunc(10)));
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_TRUE(TSome.isFullSet());
|
2017-06-05 07:03:52 +08:00
|
|
|
EXPECT_TRUE(TWrap.isFullSet());
|
2017-06-05 07:03:54 +08:00
|
|
|
|
|
|
|
// 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)));
|
2017-06-05 07:07:53 +08:00
|
|
|
|
|
|
|
// 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)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, ZExt) {
|
2009-07-10 06:07:27 +08:00
|
|
|
ConstantRange ZFull = Full.zeroExtend(20);
|
|
|
|
ConstantRange ZEmpty = Empty.zeroExtend(20);
|
|
|
|
ConstantRange ZOne = One.zeroExtend(20);
|
|
|
|
ConstantRange ZSome = Some.zeroExtend(20);
|
|
|
|
ConstantRange ZWrap = Wrap.zeroExtend(20);
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_TRUE(ZEmpty.isEmptySet());
|
2010-12-07 16:25:19 +08:00
|
|
|
EXPECT_EQ(ZOne, ConstantRange(One.getLower().zext(20),
|
|
|
|
One.getUpper().zext(20)));
|
|
|
|
EXPECT_EQ(ZSome, ConstantRange(Some.getLower().zext(20),
|
|
|
|
Some.getUpper().zext(20)));
|
2010-09-07 07:52:49 +08:00
|
|
|
EXPECT_EQ(ZWrap, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
|
2012-07-24 04:33:29 +08:00
|
|
|
|
|
|
|
// zext([5, 0), 3->7) = [5, 8)
|
|
|
|
ConstantRange FiveZero(APInt(3, 5), APInt(3, 0));
|
|
|
|
EXPECT_EQ(FiveZero.zeroExtend(7), ConstantRange(APInt(7, 5), APInt(7, 8)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, SExt) {
|
2009-07-10 06:07:27 +08:00
|
|
|
ConstantRange SFull = Full.signExtend(20);
|
|
|
|
ConstantRange SEmpty = Empty.signExtend(20);
|
|
|
|
ConstantRange SOne = One.signExtend(20);
|
|
|
|
ConstantRange SSome = Some.signExtend(20);
|
|
|
|
ConstantRange SWrap = Wrap.signExtend(20);
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
|
|
|
|
APInt(20, INT16_MAX + 1, true)));
|
2009-07-10 06:07:27 +08:00
|
|
|
EXPECT_TRUE(SEmpty.isEmptySet());
|
2010-12-07 16:25:19 +08:00
|
|
|
EXPECT_EQ(SOne, ConstantRange(One.getLower().sext(20),
|
|
|
|
One.getUpper().sext(20)));
|
|
|
|
EXPECT_EQ(SSome, ConstantRange(Some.getLower().sext(20),
|
|
|
|
Some.getUpper().sext(20)));
|
2010-09-07 07:52:49 +08:00
|
|
|
EXPECT_EQ(SWrap, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
|
|
|
|
APInt(20, INT16_MAX + 1, true)));
|
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16),
|
|
|
|
ConstantRange(APInt(16, -128), APInt(16, 128)));
|
2013-10-30 23:36:50 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(16, 0x0200), APInt(16, 0x8000)).signExtend(19),
|
|
|
|
ConstantRange(APInt(19, 0x0200), APInt(19, 0x8000)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantRangeTest, IntersectWith) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Empty.intersectWith(Full), Empty);
|
|
|
|
EXPECT_EQ(Empty.intersectWith(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.intersectWith(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.intersectWith(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.intersectWith(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Full.intersectWith(Full), Full);
|
|
|
|
EXPECT_EQ(Some.intersectWith(Some), Some);
|
|
|
|
EXPECT_EQ(Some.intersectWith(One), One);
|
|
|
|
EXPECT_EQ(Full.intersectWith(One), One);
|
|
|
|
EXPECT_EQ(Full.intersectWith(Some), Some);
|
|
|
|
EXPECT_EQ(Some.intersectWith(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.intersectWith(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One));
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-18 14:34:42 +08:00
|
|
|
// Klee generated testcase from PR4545.
|
|
|
|
// The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
|
|
|
|
// 01..4.6789ABCDEF where the dots represent values not in the intersection.
|
|
|
|
ConstantRange LHS(APInt(16, 4), APInt(16, 2));
|
|
|
|
ConstantRange RHS(APInt(16, 6), APInt(16, 5));
|
2009-08-23 14:32:25 +08:00
|
|
|
EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
|
2012-05-18 08:14:36 +08:00
|
|
|
|
|
|
|
// previous bug: intersection of [min, 3) and [2, max) should be 2
|
2012-06-28 08:59:33 +08:00
|
|
|
LHS = ConstantRange(APInt(32, -2147483646), APInt(32, 3));
|
|
|
|
RHS = ConstantRange(APInt(32, 2), APInt(32, 2147483646));
|
2012-05-18 08:14:36 +08:00
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2)));
|
2012-06-28 08:59:33 +08:00
|
|
|
|
|
|
|
// [2, 0) /\ [4, 3) = [2, 0)
|
|
|
|
LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
|
|
|
|
RHS = ConstantRange(APInt(32, 4), APInt(32, 3));
|
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 2), APInt(32, 0)));
|
|
|
|
|
|
|
|
// [2, 0) /\ [4, 2) = [4, 0)
|
|
|
|
LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
|
|
|
|
RHS = ConstantRange(APInt(32, 4), APInt(32, 2));
|
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 4), APInt(32, 0)));
|
|
|
|
|
|
|
|
// [4, 2) /\ [5, 1) = [5, 1)
|
|
|
|
LHS = ConstantRange(APInt(32, 4), APInt(32, 2));
|
|
|
|
RHS = ConstantRange(APInt(32, 5), APInt(32, 1));
|
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 5), APInt(32, 1)));
|
|
|
|
|
|
|
|
// [2, 0) /\ [7, 4) = [7, 4)
|
|
|
|
LHS = ConstantRange(APInt(32, 2), APInt(32, 0));
|
|
|
|
RHS = ConstantRange(APInt(32, 7), APInt(32, 4));
|
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 7), APInt(32, 4)));
|
|
|
|
|
|
|
|
// [4, 2) /\ [1, 0) = [1, 0)
|
|
|
|
LHS = ConstantRange(APInt(32, 4), APInt(32, 2));
|
|
|
|
RHS = ConstantRange(APInt(32, 1), APInt(32, 0));
|
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 4), APInt(32, 2)));
|
|
|
|
|
|
|
|
// [15, 0) /\ [7, 6) = [15, 0)
|
|
|
|
LHS = ConstantRange(APInt(32, 15), APInt(32, 0));
|
|
|
|
RHS = ConstantRange(APInt(32, 7), APInt(32, 6));
|
|
|
|
EXPECT_EQ(LHS.intersectWith(RHS), ConstantRange(APInt(32, 15), APInt(32, 0)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, UnionWith) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Wrap.unionWith(One),
|
|
|
|
ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
|
|
|
|
EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One));
|
|
|
|
EXPECT_EQ(Empty.unionWith(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.unionWith(Full), Full);
|
|
|
|
EXPECT_EQ(Some.unionWith(Wrap), Full);
|
2009-07-19 11:44:35 +08:00
|
|
|
|
|
|
|
// PR4545
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
|
|
|
|
ConstantRange(APInt(16, 0), APInt(16, 8))),
|
|
|
|
ConstantRange(APInt(16, 14), APInt(16, 8)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
|
|
|
|
ConstantRange(APInt(16, 4), APInt(16, 0))),
|
2009-08-23 14:32:25 +08:00
|
|
|
ConstantRange(16));
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
|
|
|
|
ConstantRange(APInt(16, 2), APInt(16, 1))),
|
2009-08-23 14:32:25 +08:00
|
|
|
ConstantRange(16));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2012-06-29 00:10:13 +08:00
|
|
|
TEST_F(ConstantRangeTest, SetDifference) {
|
|
|
|
EXPECT_EQ(Full.difference(Empty), Full);
|
|
|
|
EXPECT_EQ(Full.difference(Full), Empty);
|
|
|
|
EXPECT_EQ(Empty.difference(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.difference(Full), Empty);
|
|
|
|
|
|
|
|
ConstantRange A(APInt(16, 3), APInt(16, 7));
|
|
|
|
ConstantRange B(APInt(16, 5), APInt(16, 9));
|
|
|
|
ConstantRange C(APInt(16, 3), APInt(16, 5));
|
|
|
|
ConstantRange D(APInt(16, 7), APInt(16, 9));
|
|
|
|
ConstantRange E(APInt(16, 5), APInt(16, 4));
|
|
|
|
ConstantRange F(APInt(16, 7), APInt(16, 3));
|
|
|
|
EXPECT_EQ(A.difference(B), C);
|
|
|
|
EXPECT_EQ(B.difference(A), D);
|
|
|
|
EXPECT_EQ(E.difference(A), F);
|
|
|
|
}
|
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, SubtractAPInt) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full.subtract(APInt(16, 4)), Full);
|
|
|
|
EXPECT_EQ(Empty.subtract(APInt(16, 4)), Empty);
|
|
|
|
EXPECT_EQ(Some.subtract(APInt(16, 4)),
|
|
|
|
ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
|
|
|
|
EXPECT_EQ(Wrap.subtract(APInt(16, 4)),
|
|
|
|
ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
|
|
|
|
EXPECT_EQ(One.subtract(APInt(16, 4)),
|
|
|
|
ConstantRange(APInt(16, 0x6)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, Add) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full.add(APInt(16, 4)), Full);
|
|
|
|
EXPECT_EQ(Full.add(Full), Full);
|
|
|
|
EXPECT_EQ(Full.add(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.add(One), Full);
|
|
|
|
EXPECT_EQ(Full.add(Some), Full);
|
|
|
|
EXPECT_EQ(Full.add(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.add(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.add(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.add(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.add(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Empty.add(APInt(16, 4)), Empty);
|
|
|
|
EXPECT_EQ(Some.add(APInt(16, 4)),
|
2010-08-12 06:04:36 +08:00
|
|
|
ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Wrap.add(APInt(16, 4)),
|
2010-08-12 06:04:36 +08:00
|
|
|
ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(One.add(APInt(16, 4)),
|
2010-08-12 06:04:36 +08:00
|
|
|
ConstantRange(APInt(16, 0xe)));
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:44:23 +08:00
|
|
|
TEST_F(ConstantRangeTest, AddWithNoSignedWrap) {
|
|
|
|
EXPECT_EQ(Empty.addWithNoSignedWrap(APInt(16, 1)), Empty);
|
|
|
|
EXPECT_EQ(Full.addWithNoSignedWrap(APInt(16, 1)),
|
|
|
|
ConstantRange(APInt(16, INT16_MIN+1), APInt(16, INT16_MIN)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, -50), APInt(8, 50)).addWithNoSignedWrap(APInt(8, 10)),
|
|
|
|
ConstantRange(APInt(8, -40), APInt(8, 60)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, -50), APInt(8, 120)).addWithNoSignedWrap(APInt(8, 10)),
|
|
|
|
ConstantRange(APInt(8, -40), APInt(8, INT8_MIN)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, -10)).addWithNoSignedWrap(APInt(8, 5)),
|
|
|
|
ConstantRange(APInt(8, 125), APInt(8, -5)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, -120)).addWithNoSignedWrap(APInt(8, 10)),
|
|
|
|
ConstantRange(APInt(8, INT8_MIN+10), APInt(8, -110)));
|
|
|
|
|
|
|
|
EXPECT_EQ(Empty.addWithNoSignedWrap(APInt(16, -1)), Empty);
|
|
|
|
EXPECT_EQ(Full.addWithNoSignedWrap(APInt(16, -1)),
|
|
|
|
ConstantRange(APInt(16, INT16_MIN), APInt(16, INT16_MAX)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, -50), APInt(8, 50)).addWithNoSignedWrap(APInt(8, -10)),
|
|
|
|
ConstantRange(APInt(8, -60), APInt(8, 40)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, -120), APInt(8, 50)).addWithNoSignedWrap(APInt(8, -10)),
|
|
|
|
ConstantRange(APInt(8, INT8_MIN), APInt(8, 40)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, -120)).addWithNoSignedWrap(APInt(8, -5)),
|
|
|
|
ConstantRange(APInt(8, 115), APInt(8, -125)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, -120)).addWithNoSignedWrap(APInt(8, -10)),
|
|
|
|
ConstantRange(APInt(8, 110), APInt(8, INT8_MIN-10)));
|
|
|
|
}
|
|
|
|
|
2010-08-12 06:04:36 +08:00
|
|
|
TEST_F(ConstantRangeTest, Sub) {
|
|
|
|
EXPECT_EQ(Full.sub(APInt(16, 4)), Full);
|
|
|
|
EXPECT_EQ(Full.sub(Full), Full);
|
|
|
|
EXPECT_EQ(Full.sub(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.sub(One), Full);
|
|
|
|
EXPECT_EQ(Full.sub(Some), Full);
|
|
|
|
EXPECT_EQ(Full.sub(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.sub(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.sub(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.sub(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.sub(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Empty.sub(APInt(16, 4)), Empty);
|
|
|
|
EXPECT_EQ(Some.sub(APInt(16, 4)),
|
|
|
|
ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
|
2011-06-23 05:13:46 +08:00
|
|
|
EXPECT_EQ(Some.sub(Some),
|
|
|
|
ConstantRange(APInt(16, 0xf561), APInt(16, 0xaa0)));
|
2010-08-12 06:04:36 +08:00
|
|
|
EXPECT_EQ(Wrap.sub(APInt(16, 4)),
|
|
|
|
ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
|
|
|
|
EXPECT_EQ(One.sub(APInt(16, 4)),
|
|
|
|
ConstantRange(APInt(16, 0x6)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, Multiply) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full.multiply(Full), Full);
|
|
|
|
EXPECT_EQ(Full.multiply(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.multiply(One), Full);
|
|
|
|
EXPECT_EQ(Full.multiply(Some), Full);
|
|
|
|
EXPECT_EQ(Full.multiply(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.multiply(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.multiply(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.multiply(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.multiply(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa),
|
|
|
|
APInt(16, 0xa*0xa + 1)));
|
|
|
|
EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa),
|
|
|
|
APInt(16, 0xa*0xaa9 + 1)));
|
|
|
|
EXPECT_EQ(One.multiply(Wrap), Full);
|
|
|
|
EXPECT_EQ(Some.multiply(Some), Full);
|
|
|
|
EXPECT_EQ(Some.multiply(Wrap), Full);
|
|
|
|
EXPECT_EQ(Wrap.multiply(Wrap), Full);
|
2009-07-13 11:27:41 +08:00
|
|
|
|
2012-07-17 04:47:16 +08:00
|
|
|
ConstantRange Zero(APInt(16, 0));
|
|
|
|
EXPECT_EQ(Zero.multiply(Full), Zero);
|
|
|
|
EXPECT_EQ(Zero.multiply(Some), Zero);
|
|
|
|
EXPECT_EQ(Zero.multiply(Wrap), Zero);
|
|
|
|
EXPECT_EQ(Full.multiply(Zero), Zero);
|
|
|
|
EXPECT_EQ(Some.multiply(Zero), Zero);
|
|
|
|
EXPECT_EQ(Wrap.multiply(Zero), Zero);
|
|
|
|
|
2009-07-13 11:27:41 +08:00
|
|
|
// http://llvm.org/PR4545
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
|
|
|
|
ConstantRange(APInt(4, 6), APInt(4, 2))),
|
|
|
|
ConstantRange(4, /*isFullSet=*/true));
|
2015-03-06 23:50:47 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 0)).multiply(
|
|
|
|
ConstantRange(APInt(8, 252), APInt(8, 4))),
|
|
|
|
ConstantRange(APInt(8, 250), APInt(8, 9)));
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, 254), APInt(8, 255)).multiply(
|
|
|
|
ConstantRange(APInt(8, 2), APInt(8, 4))),
|
|
|
|
ConstantRange(APInt(8, 250), APInt(8, 253)));
|
2017-05-11 02:15:06 +08:00
|
|
|
|
|
|
|
// TODO: This should be return [-2, 0]
|
|
|
|
EXPECT_EQ(ConstantRange(APInt(8, -2)).multiply(
|
|
|
|
ConstantRange(APInt(8, 0), APInt(8, 2))),
|
2017-05-11 04:01:48 +08:00
|
|
|
ConstantRange(APInt(8, -2), APInt(8, 1)));
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantRangeTest, UMax) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full.umax(Full), Full);
|
|
|
|
EXPECT_EQ(Full.umax(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
|
|
|
|
EXPECT_EQ(Full.umax(Wrap), Full);
|
|
|
|
EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
|
|
|
|
EXPECT_EQ(Empty.umax(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.umax(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.umax(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Empty.umax(One), Empty);
|
|
|
|
EXPECT_EQ(Some.umax(Some), Some);
|
|
|
|
EXPECT_EQ(Some.umax(Wrap), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
|
|
|
|
EXPECT_EQ(Some.umax(One), Some);
|
2009-07-12 02:43:20 +08:00
|
|
|
// TODO: ConstantRange is currently over-conservative here.
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Wrap.umax(Wrap), Full);
|
|
|
|
EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
|
|
|
|
EXPECT_EQ(One.umax(One), One);
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, SMax) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full.smax(Full), Full);
|
|
|
|
EXPECT_EQ(Full.smax(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa),
|
|
|
|
APInt::getSignedMinValue(16)));
|
|
|
|
EXPECT_EQ(Full.smax(Wrap), Full);
|
|
|
|
EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa),
|
|
|
|
APInt::getSignedMinValue(16)));
|
|
|
|
EXPECT_EQ(Empty.smax(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.smax(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.smax(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Empty.smax(One), Empty);
|
|
|
|
EXPECT_EQ(Some.smax(Some), Some);
|
|
|
|
EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
|
|
|
|
APInt(16, (uint64_t)INT16_MIN)));
|
|
|
|
EXPECT_EQ(Some.smax(One), Some);
|
|
|
|
EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
|
|
|
|
APInt(16, (uint64_t)INT16_MIN)));
|
|
|
|
EXPECT_EQ(One.smax(One), One);
|
2009-07-12 02:43:20 +08:00
|
|
|
}
|
2009-07-10 06:07:27 +08:00
|
|
|
|
2016-02-27 06:08:18 +08:00
|
|
|
TEST_F(ConstantRangeTest, UMin) {
|
|
|
|
EXPECT_EQ(Full.umin(Full), Full);
|
|
|
|
EXPECT_EQ(Full.umin(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.umin(Some), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Full.umin(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.umin(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.umin(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.umin(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Empty.umin(One), Empty);
|
|
|
|
EXPECT_EQ(Some.umin(Some), Some);
|
|
|
|
EXPECT_EQ(Some.umin(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Some.umin(One), One);
|
|
|
|
// TODO: ConstantRange is currently over-conservative here.
|
|
|
|
EXPECT_EQ(Wrap.umin(Wrap), Full);
|
|
|
|
EXPECT_EQ(Wrap.umin(One), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
|
|
|
|
EXPECT_EQ(One.umin(One), One);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantRangeTest, SMin) {
|
|
|
|
EXPECT_EQ(Full.smin(Full), Full);
|
|
|
|
EXPECT_EQ(Full.smin(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.smin(Some), ConstantRange(APInt(16, (uint64_t)INT16_MIN),
|
|
|
|
APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Full.smin(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.smin(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.smin(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.smin(Wrap), Empty);
|
|
|
|
EXPECT_EQ(Empty.smin(One), Empty);
|
|
|
|
EXPECT_EQ(Some.smin(Some), Some);
|
|
|
|
EXPECT_EQ(Some.smin(Wrap), ConstantRange(APInt(16, (uint64_t)INT16_MIN),
|
|
|
|
APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Some.smin(One), One);
|
|
|
|
// TODO: ConstantRange is currently over-conservative here.
|
|
|
|
EXPECT_EQ(Wrap.smin(Wrap), Full);
|
|
|
|
EXPECT_EQ(Wrap.smin(One), ConstantRange(APInt(16, (uint64_t)INT16_MIN),
|
|
|
|
APInt(16, 0xb)));
|
|
|
|
EXPECT_EQ(One.smin(One), One);
|
|
|
|
}
|
|
|
|
|
2009-07-12 02:43:20 +08:00
|
|
|
TEST_F(ConstantRangeTest, UDiv) {
|
2009-09-06 02:27:40 +08:00
|
|
|
EXPECT_EQ(Full.udiv(Full), Full);
|
|
|
|
EXPECT_EQ(Full.udiv(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0),
|
|
|
|
APInt(16, 0xffff / 0xa + 1)));
|
|
|
|
EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0),
|
|
|
|
APInt(16, 0xffff / 0xa + 1)));
|
|
|
|
EXPECT_EQ(Full.udiv(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.udiv(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.udiv(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.udiv(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.udiv(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1)));
|
|
|
|
EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2)));
|
|
|
|
EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
|
|
|
|
EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
|
|
|
|
EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Wrap.udiv(Wrap), Full);
|
2009-07-10 06:07:27 +08:00
|
|
|
}
|
|
|
|
|
2010-08-12 06:04:36 +08:00
|
|
|
TEST_F(ConstantRangeTest, Shl) {
|
|
|
|
EXPECT_EQ(Full.shl(Full), Full);
|
|
|
|
EXPECT_EQ(Full.shl(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.shl(One), Full); // TODO: [0, (-1 << 0xa) + 1)
|
|
|
|
EXPECT_EQ(Full.shl(Some), Full); // TODO: [0, (-1 << 0xa) + 1)
|
|
|
|
EXPECT_EQ(Full.shl(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.shl(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.shl(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.shl(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.shl(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.shl(One), ConstantRange(APInt(16, 0xa << 0xa),
|
|
|
|
APInt(16, (0xa << 0xa) + 1)));
|
|
|
|
EXPECT_EQ(One.shl(Some), Full); // TODO: [0xa << 0xa, 0)
|
|
|
|
EXPECT_EQ(One.shl(Wrap), Full); // TODO: [0xa, 0xa << 14 + 1)
|
|
|
|
EXPECT_EQ(Some.shl(Some), Full); // TODO: [0xa << 0xa, 0xfc01)
|
|
|
|
EXPECT_EQ(Some.shl(Wrap), Full); // TODO: [0xa, 0x7ff << 0x5 + 1)
|
|
|
|
EXPECT_EQ(Wrap.shl(Wrap), Full);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ConstantRangeTest, Lshr) {
|
|
|
|
EXPECT_EQ(Full.lshr(Full), Full);
|
|
|
|
EXPECT_EQ(Full.lshr(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.lshr(One), ConstantRange(APInt(16, 0),
|
|
|
|
APInt(16, (0xffff >> 0xa) + 1)));
|
|
|
|
EXPECT_EQ(Full.lshr(Some), ConstantRange(APInt(16, 0),
|
|
|
|
APInt(16, (0xffff >> 0xa) + 1)));
|
|
|
|
EXPECT_EQ(Full.lshr(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.lshr(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.lshr(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.lshr(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.lshr(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.lshr(One), ConstantRange(APInt(16, 0)));
|
|
|
|
EXPECT_EQ(One.lshr(Some), ConstantRange(APInt(16, 0)));
|
|
|
|
EXPECT_EQ(One.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
|
|
|
|
EXPECT_EQ(Some.lshr(Some), ConstantRange(APInt(16, 0),
|
|
|
|
APInt(16, (0xaaa >> 0xa) + 1)));
|
|
|
|
EXPECT_EQ(Some.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Wrap.lshr(Wrap), Full);
|
|
|
|
}
|
|
|
|
|
2017-12-18 21:01:32 +08:00
|
|
|
TEST_F(ConstantRangeTest, Ashr) {
|
|
|
|
EXPECT_EQ(Full.ashr(Full), Full);
|
|
|
|
EXPECT_EQ(Full.ashr(Empty), Empty);
|
|
|
|
EXPECT_EQ(Full.ashr(One), ConstantRange(APInt(16, 0xffe0),
|
|
|
|
APInt(16, (0x7fff >> 0xa) + 1 )));
|
|
|
|
ConstantRange Small(APInt(16, 0xa), APInt(16, 0xb));
|
|
|
|
EXPECT_EQ(Full.ashr(Small), ConstantRange(APInt(16, 0xffe0),
|
|
|
|
APInt(16, (0x7fff >> 0xa) + 1 )));
|
|
|
|
EXPECT_EQ(Full.ashr(Some), ConstantRange(APInt(16, 0xffe0),
|
|
|
|
APInt(16, (0x7fff >> 0xa) + 1 )));
|
|
|
|
EXPECT_EQ(Full.ashr(Wrap), Full);
|
|
|
|
EXPECT_EQ(Empty.ashr(Empty), Empty);
|
|
|
|
EXPECT_EQ(Empty.ashr(One), Empty);
|
|
|
|
EXPECT_EQ(Empty.ashr(Some), Empty);
|
|
|
|
EXPECT_EQ(Empty.ashr(Wrap), Empty);
|
|
|
|
EXPECT_EQ(One.ashr(One), ConstantRange(APInt(16, 0)));
|
|
|
|
EXPECT_EQ(One.ashr(Some), ConstantRange(APInt(16, 0)));
|
|
|
|
EXPECT_EQ(One.ashr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
|
|
|
|
EXPECT_EQ(Some.ashr(Some), ConstantRange(APInt(16, 0),
|
|
|
|
APInt(16, (0xaaa >> 0xa) + 1)));
|
|
|
|
EXPECT_EQ(Some.ashr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
|
|
|
|
EXPECT_EQ(Wrap.ashr(Wrap), Full);
|
|
|
|
ConstantRange Neg(APInt(16, 0xf3f0, true), APInt(16, 0xf7f8, true));
|
|
|
|
EXPECT_EQ(Neg.ashr(Small), ConstantRange(APInt(16, 0xfffc, true),
|
|
|
|
APInt(16, 0xfffe, true)));
|
|
|
|
}
|
|
|
|
|
2015-03-18 08:41:24 +08:00
|
|
|
TEST(ConstantRange, MakeAllowedICmpRegion) {
|
2010-09-29 02:18:36 +08:00
|
|
|
// PR8250
|
|
|
|
ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32));
|
2015-03-18 08:41:24 +08:00
|
|
|
EXPECT_TRUE(ConstantRange::makeAllowedICmpRegion(ICmpInst::ICMP_SGT, SMax)
|
|
|
|
.isEmptySet());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConstantRange, MakeSatisfyingICmpRegion) {
|
|
|
|
ConstantRange LowHalf(APInt(8, 0), APInt(8, 128));
|
|
|
|
ConstantRange HighHalf(APInt(8, 128), APInt(8, 0));
|
|
|
|
ConstantRange EmptySet(8, /* isFullSet = */ false);
|
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, LowHalf),
|
|
|
|
HighHalf);
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_NE, HighHalf),
|
|
|
|
LowHalf);
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_EQ,
|
|
|
|
HighHalf).isEmptySet());
|
|
|
|
|
|
|
|
ConstantRange UnsignedSample(APInt(8, 5), APInt(8, 200));
|
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULT,
|
|
|
|
UnsignedSample),
|
|
|
|
ConstantRange(APInt(8, 0), APInt(8, 5)));
|
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_ULE,
|
|
|
|
UnsignedSample),
|
|
|
|
ConstantRange(APInt(8, 0), APInt(8, 6)));
|
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGT,
|
|
|
|
UnsignedSample),
|
|
|
|
ConstantRange(APInt(8, 200), APInt(8, 0)));
|
|
|
|
|
|
|
|
EXPECT_EQ(ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_UGE,
|
|
|
|
UnsignedSample),
|
|
|
|
ConstantRange(APInt(8, 199), APInt(8, 0)));
|
|
|
|
|
|
|
|
ConstantRange SignedSample(APInt(8, -5), APInt(8, 5));
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLT, SignedSample),
|
|
|
|
ConstantRange(APInt(8, -128), APInt(8, -5)));
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SLE, SignedSample),
|
|
|
|
ConstantRange(APInt(8, -128), APInt(8, -4)));
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGT, SignedSample),
|
|
|
|
ConstantRange(APInt(8, 5), APInt(8, -128)));
|
|
|
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeSatisfyingICmpRegion(ICmpInst::ICMP_SGE, SignedSample),
|
|
|
|
ConstantRange(APInt(8, 4), APInt(8, -128)));
|
2010-09-29 02:18:36 +08:00
|
|
|
}
|
|
|
|
|
2016-03-04 02:31:33 +08:00
|
|
|
TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
|
2015-10-22 11:12:57 +08:00
|
|
|
const int IntMin4Bits = 8;
|
|
|
|
const int IntMax4Bits = 7;
|
|
|
|
typedef OverflowingBinaryOperator OBO;
|
|
|
|
|
|
|
|
for (int Const : {0, -1, -2, 1, 2, IntMin4Bits, IntMax4Bits}) {
|
|
|
|
APInt C(4, Const, true /* = isSigned */);
|
|
|
|
|
2016-02-23 00:13:02 +08:00
|
|
|
auto NUWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, C, OBO::NoUnsignedWrap);
|
2015-10-22 11:12:57 +08:00
|
|
|
|
|
|
|
EXPECT_FALSE(NUWRegion.isEmptySet());
|
|
|
|
|
2016-02-23 00:13:02 +08:00
|
|
|
auto NSWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, C, OBO::NoSignedWrap);
|
2015-10-22 11:12:57 +08:00
|
|
|
|
|
|
|
EXPECT_FALSE(NSWRegion.isEmptySet());
|
|
|
|
|
2016-02-23 00:13:02 +08:00
|
|
|
auto NoWrapRegion = ConstantRange::makeGuaranteedNoWrapRegion(
|
2015-10-22 11:12:57 +08:00
|
|
|
Instruction::Add, C, OBO::NoSignedWrap | OBO::NoUnsignedWrap);
|
|
|
|
|
|
|
|
EXPECT_FALSE(NoWrapRegion.isEmptySet());
|
|
|
|
EXPECT_TRUE(NUWRegion.intersectWith(NSWRegion).contains(NoWrapRegion));
|
|
|
|
|
|
|
|
for (APInt I = NUWRegion.getLower(), E = NUWRegion.getUpper(); I != E;
|
|
|
|
++I) {
|
|
|
|
bool Overflow = false;
|
2017-04-20 06:11:05 +08:00
|
|
|
(void)I.uadd_ov(C, Overflow);
|
2015-10-22 11:12:57 +08:00
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (APInt I = NSWRegion.getLower(), E = NSWRegion.getUpper(); I != E;
|
|
|
|
++I) {
|
|
|
|
bool Overflow = false;
|
2017-04-20 06:11:05 +08:00
|
|
|
(void)I.sadd_ov(C, Overflow);
|
2015-10-22 11:12:57 +08:00
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (APInt I = NoWrapRegion.getLower(), E = NoWrapRegion.getUpper(); I != E;
|
|
|
|
++I) {
|
|
|
|
bool Overflow = false;
|
|
|
|
|
2017-04-20 06:11:05 +08:00
|
|
|
(void)I.sadd_ov(C, Overflow);
|
2015-10-22 11:12:57 +08:00
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
|
2017-04-20 06:11:05 +08:00
|
|
|
(void)I.uadd_ov(C, Overflow);
|
2015-10-22 11:12:57 +08:00
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
}
|
|
|
|
}
|
2016-03-04 02:31:16 +08:00
|
|
|
|
2017-12-06 02:14:23 +08:00
|
|
|
for (int Const : {0, -1, -2, 1, 2, IntMin4Bits, IntMax4Bits}) {
|
|
|
|
APInt C(4, Const, true /* = isSigned */);
|
|
|
|
|
|
|
|
auto NUWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, C, OBO::NoUnsignedWrap);
|
|
|
|
|
|
|
|
EXPECT_FALSE(NUWRegion.isEmptySet());
|
|
|
|
|
|
|
|
auto NSWRegion = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, C, OBO::NoSignedWrap);
|
|
|
|
|
|
|
|
EXPECT_FALSE(NSWRegion.isEmptySet());
|
|
|
|
|
|
|
|
auto NoWrapRegion = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, C, OBO::NoSignedWrap | OBO::NoUnsignedWrap);
|
|
|
|
|
|
|
|
EXPECT_FALSE(NoWrapRegion.isEmptySet());
|
|
|
|
EXPECT_TRUE(NUWRegion.intersectWith(NSWRegion).contains(NoWrapRegion));
|
|
|
|
|
|
|
|
for (APInt I = NUWRegion.getLower(), E = NUWRegion.getUpper(); I != E;
|
|
|
|
++I) {
|
|
|
|
bool Overflow = false;
|
|
|
|
(void)I.usub_ov(C, Overflow);
|
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (APInt I = NSWRegion.getLower(), E = NSWRegion.getUpper(); I != E;
|
|
|
|
++I) {
|
|
|
|
bool Overflow = false;
|
|
|
|
(void)I.ssub_ov(C, Overflow);
|
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (APInt I = NoWrapRegion.getLower(), E = NoWrapRegion.getUpper(); I != E;
|
|
|
|
++I) {
|
|
|
|
bool Overflow = false;
|
|
|
|
|
|
|
|
(void)I.ssub_ov(C, Overflow);
|
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
|
|
|
|
(void)I.usub_ov(C, Overflow);
|
|
|
|
EXPECT_FALSE(Overflow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 02:31:16 +08:00
|
|
|
auto NSWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, ConstantRange(32, /* isFullSet = */ true),
|
|
|
|
OBO::NoSignedWrap);
|
|
|
|
EXPECT_TRUE(NSWForAllValues.isSingleElement() &&
|
|
|
|
NSWForAllValues.getSingleElement()->isMinValue());
|
|
|
|
|
2017-12-06 02:14:23 +08:00
|
|
|
NSWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, ConstantRange(32, /* isFullSet = */ true),
|
|
|
|
OBO::NoSignedWrap);
|
|
|
|
EXPECT_TRUE(NSWForAllValues.isSingleElement() &&
|
|
|
|
NSWForAllValues.getSingleElement()->isMaxValue());
|
|
|
|
|
2016-03-04 02:31:16 +08:00
|
|
|
auto NUWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, ConstantRange(32, /* isFullSet = */ true),
|
|
|
|
OBO::NoUnsignedWrap);
|
|
|
|
EXPECT_TRUE(NUWForAllValues.isSingleElement() &&
|
2017-05-15 12:40:19 +08:00
|
|
|
NUWForAllValues.getSingleElement()->isMinValue());
|
2016-03-04 02:31:16 +08:00
|
|
|
|
2017-12-06 02:14:23 +08:00
|
|
|
NUWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, ConstantRange(32, /* isFullSet = */ true),
|
|
|
|
OBO::NoUnsignedWrap);
|
|
|
|
EXPECT_TRUE(NUWForAllValues.isSingleElement() &&
|
|
|
|
NUWForAllValues.getSingleElement()->isMaxValue());
|
|
|
|
|
2016-03-04 02:31:16 +08:00
|
|
|
auto NUWAndNSWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, ConstantRange(32, /* isFullSet = */ true),
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap);
|
|
|
|
EXPECT_TRUE(NUWAndNSWForAllValues.isSingleElement() &&
|
2017-05-15 12:40:19 +08:00
|
|
|
NUWAndNSWForAllValues.getSingleElement()->isMinValue());
|
2016-03-04 02:31:16 +08:00
|
|
|
|
2017-12-06 02:14:23 +08:00
|
|
|
NUWAndNSWForAllValues = ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, ConstantRange(32, /* isFullSet = */ true),
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap);
|
|
|
|
EXPECT_TRUE(NUWAndNSWForAllValues.isSingleElement() &&
|
|
|
|
NUWAndNSWForAllValues.getSingleElement()->isMaxValue());
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, APInt(32, 0), OBO::NoUnsignedWrap).isFullSet());
|
|
|
|
EXPECT_TRUE(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, APInt(32, 0), OBO::NoSignedWrap).isFullSet());
|
|
|
|
EXPECT_TRUE(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, APInt(32, 0),
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap).isFullSet());
|
|
|
|
EXPECT_TRUE(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, APInt(32, 0), OBO::NoUnsignedWrap).isFullSet());
|
|
|
|
EXPECT_TRUE(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, APInt(32, 0), OBO::NoSignedWrap).isFullSet());
|
|
|
|
EXPECT_TRUE(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, APInt(32, 0),
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap).isFullSet());
|
|
|
|
|
2016-03-04 02:31:16 +08:00
|
|
|
ConstantRange OneToFive(APInt(32, 1), APInt(32, 6));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, OneToFive, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32),
|
|
|
|
APInt::getSignedMaxValue(32) - 4));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, OneToFive, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32), APInt::getMinValue(32) - 5));
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, OneToFive, OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32), APInt::getSignedMaxValue(32) - 4));
|
2017-12-06 02:14:23 +08:00
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, OneToFive, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32) + 5,
|
|
|
|
APInt::getSignedMinValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, OneToFive, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32) + 5, APInt::getMinValue(32)));
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, OneToFive, OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32) + 5, APInt::getSignedMinValue(32)));
|
2016-03-04 02:31:16 +08:00
|
|
|
|
|
|
|
ConstantRange MinusFiveToMinusTwo(APInt(32, -5), APInt(32, -1));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, MinusFiveToMinusTwo, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32) + 5,
|
|
|
|
APInt::getSignedMinValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, MinusFiveToMinusTwo, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt(32, 0), APInt(32, 2)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, MinusFiveToMinusTwo,
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt(32, 0), APInt(32, 2)));
|
2017-12-06 02:14:23 +08:00
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, MinusFiveToMinusTwo, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32),
|
|
|
|
APInt::getSignedMaxValue(32) - 4));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, MinusFiveToMinusTwo, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt::getMaxValue(32) - 1,
|
|
|
|
APInt::getMinValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, MinusFiveToMinusTwo,
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getMaxValue(32) - 1,
|
|
|
|
APInt::getMinValue(32)));
|
2016-03-04 02:31:16 +08:00
|
|
|
|
|
|
|
ConstantRange MinusOneToOne(APInt(32, -1), APInt(32, 2));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, MinusOneToOne, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32) + 1,
|
|
|
|
APInt::getSignedMinValue(32) - 1));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, MinusOneToOne, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt(32, 0), APInt(32, 1)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, MinusOneToOne,
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt(32, 0), APInt(32, 1)));
|
2017-12-06 02:14:23 +08:00
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, MinusOneToOne, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32) + 1,
|
|
|
|
APInt::getSignedMinValue(32) - 1));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, MinusOneToOne, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt::getMaxValue(32),
|
|
|
|
APInt::getMinValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, MinusOneToOne,
|
|
|
|
OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getMaxValue(32),
|
|
|
|
APInt::getMinValue(32)));
|
|
|
|
|
|
|
|
ConstantRange One(APInt(32, 1), APInt(32, 2));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, One, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32),
|
|
|
|
APInt::getSignedMaxValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, One, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32), APInt::getMaxValue(32)));
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Add, One, OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt(32, 0), APInt::getSignedMaxValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, One, OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getSignedMinValue(32) + 1,
|
|
|
|
APInt::getSignedMinValue(32)));
|
|
|
|
EXPECT_EQ(ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, One, OBO::NoUnsignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32) + 1, APInt::getMinValue(32)));
|
|
|
|
EXPECT_EQ(
|
|
|
|
ConstantRange::makeGuaranteedNoWrapRegion(
|
|
|
|
Instruction::Sub, One, OBO::NoUnsignedWrap | OBO::NoSignedWrap),
|
|
|
|
ConstantRange(APInt::getMinValue(32) + 1, APInt::getSignedMinValue(32)));
|
2015-10-22 11:12:57 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 11:53:06 +08:00
|
|
|
TEST(ConstantRange, GetEquivalentICmp) {
|
|
|
|
APInt RHS;
|
|
|
|
CmpInst::Predicate Pred;
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt::getMinValue(32), APInt(32, 100))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_ULT);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 100));
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt::getSignedMinValue(32), APInt(32, 100))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_SLT);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 100));
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(32, 100), APInt::getMinValue(32))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_UGE);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 100));
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(32, 100), APInt::getSignedMinValue(32))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_SGE);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 100));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
ConstantRange(32, /*isFullSet=*/true).getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_UGE);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 0));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
ConstantRange(32, /*isFullSet=*/false).getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_ULT);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 0));
|
|
|
|
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt(32, 100), APInt(32, 200))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
|
|
|
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt::getSignedMinValue(32) - APInt(32, 100),
|
|
|
|
APInt::getSignedMinValue(32) + APInt(32, 100))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
|
|
|
|
|
|
|
EXPECT_FALSE(ConstantRange(APInt::getMinValue(32) - APInt(32, 100),
|
|
|
|
APInt::getMinValue(32) + APInt(32, 100))
|
|
|
|
.getEquivalentICmp(Pred, RHS));
|
2016-10-03 04:59:05 +08:00
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(32, 100)).getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_EQ);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 100));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
ConstantRange(APInt(32, 100)).inverse().getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 100));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
ConstantRange(APInt(512, 100)).inverse().getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
|
|
|
|
EXPECT_EQ(RHS, APInt(512, 100));
|
|
|
|
|
|
|
|
// NB! It would be correct for the following four calls to getEquivalentICmp
|
|
|
|
// to return ordered predicates like CmpInst::ICMP_ULT or CmpInst::ICMP_UGT.
|
|
|
|
// However, that's not the case today.
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(32, 0)).getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_EQ);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 0));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
ConstantRange(APInt(32, 0)).inverse().getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, 0));
|
|
|
|
|
|
|
|
EXPECT_TRUE(ConstantRange(APInt(32, -1)).getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_EQ);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, -1));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
ConstantRange(APInt(32, -1)).inverse().getEquivalentICmp(Pred, RHS));
|
|
|
|
EXPECT_EQ(Pred, CmpInst::ICMP_NE);
|
|
|
|
EXPECT_EQ(RHS, APInt(32, -1));
|
2016-05-19 11:53:06 +08:00
|
|
|
}
|
|
|
|
|
2009-07-10 06:07:27 +08:00
|
|
|
} // anonymous namespace
|