Home | History | Annotate | Download | only in Support
      1 //===- llvm/unittest/Support/ConstantRangeTest.cpp - ConstantRange 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/Support/ConstantRange.h"
     11 #include "llvm/Instructions.h"
     12 
     13 #include "gtest/gtest.h"
     14 
     15 using namespace llvm;
     16 
     17 namespace {
     18 
     19 class ConstantRangeTest : public ::testing::Test {
     20 protected:
     21   static ConstantRange Full;
     22   static ConstantRange Empty;
     23   static ConstantRange One;
     24   static ConstantRange Some;
     25   static ConstantRange Wrap;
     26 };
     27 
     28 ConstantRange ConstantRangeTest::Full(16);
     29 ConstantRange ConstantRangeTest::Empty(16, false);
     30 ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
     31 ConstantRange ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa));
     32 ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
     33 
     34 TEST_F(ConstantRangeTest, Basics) {
     35   EXPECT_TRUE(Full.isFullSet());
     36   EXPECT_FALSE(Full.isEmptySet());
     37   EXPECT_TRUE(Full.inverse().isEmptySet());
     38   EXPECT_FALSE(Full.isWrappedSet());
     39   EXPECT_TRUE(Full.contains(APInt(16, 0x0)));
     40   EXPECT_TRUE(Full.contains(APInt(16, 0x9)));
     41   EXPECT_TRUE(Full.contains(APInt(16, 0xa)));
     42   EXPECT_TRUE(Full.contains(APInt(16, 0xaa9)));
     43   EXPECT_TRUE(Full.contains(APInt(16, 0xaaa)));
     44 
     45   EXPECT_FALSE(Empty.isFullSet());
     46   EXPECT_TRUE(Empty.isEmptySet());
     47   EXPECT_TRUE(Empty.inverse().isFullSet());
     48   EXPECT_FALSE(Empty.isWrappedSet());
     49   EXPECT_FALSE(Empty.contains(APInt(16, 0x0)));
     50   EXPECT_FALSE(Empty.contains(APInt(16, 0x9)));
     51   EXPECT_FALSE(Empty.contains(APInt(16, 0xa)));
     52   EXPECT_FALSE(Empty.contains(APInt(16, 0xaa9)));
     53   EXPECT_FALSE(Empty.contains(APInt(16, 0xaaa)));
     54 
     55   EXPECT_FALSE(One.isFullSet());
     56   EXPECT_FALSE(One.isEmptySet());
     57   EXPECT_FALSE(One.isWrappedSet());
     58   EXPECT_FALSE(One.contains(APInt(16, 0x0)));
     59   EXPECT_FALSE(One.contains(APInt(16, 0x9)));
     60   EXPECT_TRUE(One.contains(APInt(16, 0xa)));
     61   EXPECT_FALSE(One.contains(APInt(16, 0xaa9)));
     62   EXPECT_FALSE(One.contains(APInt(16, 0xaaa)));
     63   EXPECT_FALSE(One.inverse().contains(APInt(16, 0xa)));
     64 
     65   EXPECT_FALSE(Some.isFullSet());
     66   EXPECT_FALSE(Some.isEmptySet());
     67   EXPECT_FALSE(Some.isWrappedSet());
     68   EXPECT_FALSE(Some.contains(APInt(16, 0x0)));
     69   EXPECT_FALSE(Some.contains(APInt(16, 0x9)));
     70   EXPECT_TRUE(Some.contains(APInt(16, 0xa)));
     71   EXPECT_TRUE(Some.contains(APInt(16, 0xaa9)));
     72   EXPECT_FALSE(Some.contains(APInt(16, 0xaaa)));
     73 
     74   EXPECT_FALSE(Wrap.isFullSet());
     75   EXPECT_FALSE(Wrap.isEmptySet());
     76   EXPECT_TRUE(Wrap.isWrappedSet());
     77   EXPECT_TRUE(Wrap.contains(APInt(16, 0x0)));
     78   EXPECT_TRUE(Wrap.contains(APInt(16, 0x9)));
     79   EXPECT_FALSE(Wrap.contains(APInt(16, 0xa)));
     80   EXPECT_FALSE(Wrap.contains(APInt(16, 0xaa9)));
     81   EXPECT_TRUE(Wrap.contains(APInt(16, 0xaaa)));
     82 }
     83 
     84 TEST_F(ConstantRangeTest, Equality) {
     85   EXPECT_EQ(Full, Full);
     86   EXPECT_EQ(Empty, Empty);
     87   EXPECT_EQ(One, One);
     88   EXPECT_EQ(Some, Some);
     89   EXPECT_EQ(Wrap, Wrap);
     90   EXPECT_NE(Full, Empty);
     91   EXPECT_NE(Full, One);
     92   EXPECT_NE(Full, Some);
     93   EXPECT_NE(Full, Wrap);
     94   EXPECT_NE(Empty, One);
     95   EXPECT_NE(Empty, Some);
     96   EXPECT_NE(Empty, Wrap);
     97   EXPECT_NE(One, Some);
     98   EXPECT_NE(One, Wrap);
     99   EXPECT_NE(Some, Wrap);
    100 }
    101 
    102 TEST_F(ConstantRangeTest, SingleElement) {
    103   EXPECT_EQ(Full.getSingleElement(), static_cast<APInt *>(NULL));
    104   EXPECT_EQ(Empty.getSingleElement(), static_cast<APInt *>(NULL));
    105   EXPECT_EQ(*One.getSingleElement(), APInt(16, 0xa));
    106   EXPECT_EQ(Some.getSingleElement(), static_cast<APInt *>(NULL));
    107   EXPECT_EQ(Wrap.getSingleElement(), static_cast<APInt *>(NULL));
    108 
    109   EXPECT_FALSE(Full.isSingleElement());
    110   EXPECT_FALSE(Empty.isSingleElement());
    111   EXPECT_TRUE(One.isSingleElement());
    112   EXPECT_FALSE(Some.isSingleElement());
    113   EXPECT_FALSE(Wrap.isSingleElement());
    114 }
    115 
    116 TEST_F(ConstantRangeTest, GetSetSize) {
    117   EXPECT_EQ(Full.getSetSize(), APInt(16, 0));
    118   EXPECT_EQ(Empty.getSetSize(), APInt(16, 0));
    119   EXPECT_EQ(One.getSetSize(), APInt(16, 1));
    120   EXPECT_EQ(Some.getSetSize(), APInt(16, 0xaa0));
    121   EXPECT_EQ(Wrap.getSetSize(), APInt(16, 0x10000 - 0xaa0));
    122 }
    123 
    124 TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
    125   EXPECT_EQ(Full.getUnsignedMax(), APInt(16, UINT16_MAX));
    126   EXPECT_EQ(One.getUnsignedMax(), APInt(16, 0xa));
    127   EXPECT_EQ(Some.getUnsignedMax(), APInt(16, 0xaa9));
    128   EXPECT_EQ(Wrap.getUnsignedMax(), APInt(16, UINT16_MAX));
    129 
    130   EXPECT_EQ(Full.getUnsignedMin(), APInt(16, 0));
    131   EXPECT_EQ(One.getUnsignedMin(), APInt(16, 0xa));
    132   EXPECT_EQ(Some.getUnsignedMin(), APInt(16, 0xa));
    133   EXPECT_EQ(Wrap.getUnsignedMin(), APInt(16, 0));
    134 
    135   EXPECT_EQ(Full.getSignedMax(), APInt(16, INT16_MAX));
    136   EXPECT_EQ(One.getSignedMax(), APInt(16, 0xa));
    137   EXPECT_EQ(Some.getSignedMax(), APInt(16, 0xaa9));
    138   EXPECT_EQ(Wrap.getSignedMax(), APInt(16, INT16_MAX));
    139 
    140   EXPECT_EQ(Full.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
    141   EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa));
    142   EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa));
    143   EXPECT_EQ(Wrap.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
    144 
    145   // Found by Klee
    146   EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(),
    147             APInt(4, 7));
    148 }
    149 
    150 TEST_F(ConstantRangeTest, SignWrapped) {
    151   EXPECT_TRUE(Full.isSignWrappedSet());
    152   EXPECT_FALSE(Empty.isSignWrappedSet());
    153   EXPECT_FALSE(One.isSignWrappedSet());
    154   EXPECT_FALSE(Some.isSignWrappedSet());
    155   EXPECT_TRUE(Wrap.isSignWrappedSet());
    156 
    157   EXPECT_FALSE(ConstantRange(APInt(8, 127), APInt(8, 128)).isSignWrappedSet());
    158   EXPECT_TRUE(ConstantRange(APInt(8, 127), APInt(8, 129)).isSignWrappedSet());
    159   EXPECT_FALSE(ConstantRange(APInt(8, 128), APInt(8, 129)).isSignWrappedSet());
    160   EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 9)).isSignWrappedSet());
    161   EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 250)).isSignWrappedSet());
    162   EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 10)).isSignWrappedSet());
    163   EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 251)).isSignWrappedSet());
    164 }
    165 
    166 TEST_F(ConstantRangeTest, Trunc) {
    167   ConstantRange TFull = Full.truncate(10);
    168   ConstantRange TEmpty = Empty.truncate(10);
    169   ConstantRange TOne = One.truncate(10);
    170   ConstantRange TSome = Some.truncate(10);
    171   ConstantRange TWrap = Wrap.truncate(10);
    172   EXPECT_TRUE(TFull.isFullSet());
    173   EXPECT_TRUE(TEmpty.isEmptySet());
    174   EXPECT_EQ(TOne, ConstantRange(One.getLower().trunc(10),
    175                                 One.getUpper().trunc(10)));
    176   EXPECT_TRUE(TSome.isFullSet());
    177 }
    178 
    179 TEST_F(ConstantRangeTest, ZExt) {
    180   ConstantRange ZFull = Full.zeroExtend(20);
    181   ConstantRange ZEmpty = Empty.zeroExtend(20);
    182   ConstantRange ZOne = One.zeroExtend(20);
    183   ConstantRange ZSome = Some.zeroExtend(20);
    184   ConstantRange ZWrap = Wrap.zeroExtend(20);
    185   EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
    186   EXPECT_TRUE(ZEmpty.isEmptySet());
    187   EXPECT_EQ(ZOne, ConstantRange(One.getLower().zext(20),
    188                                 One.getUpper().zext(20)));
    189   EXPECT_EQ(ZSome, ConstantRange(Some.getLower().zext(20),
    190                                  Some.getUpper().zext(20)));
    191   EXPECT_EQ(ZWrap, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
    192 }
    193 
    194 TEST_F(ConstantRangeTest, SExt) {
    195   ConstantRange SFull = Full.signExtend(20);
    196   ConstantRange SEmpty = Empty.signExtend(20);
    197   ConstantRange SOne = One.signExtend(20);
    198   ConstantRange SSome = Some.signExtend(20);
    199   ConstantRange SWrap = Wrap.signExtend(20);
    200   EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
    201                                  APInt(20, INT16_MAX + 1, true)));
    202   EXPECT_TRUE(SEmpty.isEmptySet());
    203   EXPECT_EQ(SOne, ConstantRange(One.getLower().sext(20),
    204                                 One.getUpper().sext(20)));
    205   EXPECT_EQ(SSome, ConstantRange(Some.getLower().sext(20),
    206                                  Some.getUpper().sext(20)));
    207   EXPECT_EQ(SWrap, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
    208                                  APInt(20, INT16_MAX + 1, true)));
    209 
    210   EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16),
    211             ConstantRange(APInt(16, -128), APInt(16, 128)));
    212 }
    213 
    214 TEST_F(ConstantRangeTest, IntersectWith) {
    215   EXPECT_EQ(Empty.intersectWith(Full), Empty);
    216   EXPECT_EQ(Empty.intersectWith(Empty), Empty);
    217   EXPECT_EQ(Empty.intersectWith(One), Empty);
    218   EXPECT_EQ(Empty.intersectWith(Some), Empty);
    219   EXPECT_EQ(Empty.intersectWith(Wrap), Empty);
    220   EXPECT_EQ(Full.intersectWith(Full), Full);
    221   EXPECT_EQ(Some.intersectWith(Some), Some);
    222   EXPECT_EQ(Some.intersectWith(One), One);
    223   EXPECT_EQ(Full.intersectWith(One), One);
    224   EXPECT_EQ(Full.intersectWith(Some), Some);
    225   EXPECT_EQ(Some.intersectWith(Wrap), Empty);
    226   EXPECT_EQ(One.intersectWith(Wrap), Empty);
    227   EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One));
    228 
    229   // Klee generated testcase from PR4545.
    230   // The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
    231   // 01..4.6789ABCDEF where the dots represent values not in the intersection.
    232   ConstantRange LHS(APInt(16, 4), APInt(16, 2));
    233   ConstantRange RHS(APInt(16, 6), APInt(16, 5));
    234   EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
    235 }
    236 
    237 TEST_F(ConstantRangeTest, UnionWith) {
    238   EXPECT_EQ(Wrap.unionWith(One),
    239             ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
    240   EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One));
    241   EXPECT_EQ(Empty.unionWith(Empty), Empty);
    242   EXPECT_EQ(Full.unionWith(Full), Full);
    243   EXPECT_EQ(Some.unionWith(Wrap), Full);
    244 
    245   // PR4545
    246   EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
    247                                     ConstantRange(APInt(16, 0), APInt(16, 8))),
    248             ConstantRange(APInt(16, 14), APInt(16, 8)));
    249   EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
    250                                     ConstantRange(APInt(16, 4), APInt(16, 0))),
    251               ConstantRange(16));
    252   EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
    253                                     ConstantRange(APInt(16, 2), APInt(16, 1))),
    254               ConstantRange(16));
    255 }
    256 
    257 TEST_F(ConstantRangeTest, SubtractAPInt) {
    258   EXPECT_EQ(Full.subtract(APInt(16, 4)), Full);
    259   EXPECT_EQ(Empty.subtract(APInt(16, 4)), Empty);
    260   EXPECT_EQ(Some.subtract(APInt(16, 4)),
    261             ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
    262   EXPECT_EQ(Wrap.subtract(APInt(16, 4)),
    263             ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
    264   EXPECT_EQ(One.subtract(APInt(16, 4)),
    265             ConstantRange(APInt(16, 0x6)));
    266 }
    267 
    268 TEST_F(ConstantRangeTest, Add) {
    269   EXPECT_EQ(Full.add(APInt(16, 4)), Full);
    270   EXPECT_EQ(Full.add(Full), Full);
    271   EXPECT_EQ(Full.add(Empty), Empty);
    272   EXPECT_EQ(Full.add(One), Full);
    273   EXPECT_EQ(Full.add(Some), Full);
    274   EXPECT_EQ(Full.add(Wrap), Full);
    275   EXPECT_EQ(Empty.add(Empty), Empty);
    276   EXPECT_EQ(Empty.add(One), Empty);
    277   EXPECT_EQ(Empty.add(Some), Empty);
    278   EXPECT_EQ(Empty.add(Wrap), Empty);
    279   EXPECT_EQ(Empty.add(APInt(16, 4)), Empty);
    280   EXPECT_EQ(Some.add(APInt(16, 4)),
    281             ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
    282   EXPECT_EQ(Wrap.add(APInt(16, 4)),
    283             ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
    284   EXPECT_EQ(One.add(APInt(16, 4)),
    285             ConstantRange(APInt(16, 0xe)));
    286 }
    287 
    288 TEST_F(ConstantRangeTest, Sub) {
    289   EXPECT_EQ(Full.sub(APInt(16, 4)), Full);
    290   EXPECT_EQ(Full.sub(Full), Full);
    291   EXPECT_EQ(Full.sub(Empty), Empty);
    292   EXPECT_EQ(Full.sub(One), Full);
    293   EXPECT_EQ(Full.sub(Some), Full);
    294   EXPECT_EQ(Full.sub(Wrap), Full);
    295   EXPECT_EQ(Empty.sub(Empty), Empty);
    296   EXPECT_EQ(Empty.sub(One), Empty);
    297   EXPECT_EQ(Empty.sub(Some), Empty);
    298   EXPECT_EQ(Empty.sub(Wrap), Empty);
    299   EXPECT_EQ(Empty.sub(APInt(16, 4)), Empty);
    300   EXPECT_EQ(Some.sub(APInt(16, 4)),
    301             ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
    302   EXPECT_EQ(Some.sub(Some),
    303             ConstantRange(APInt(16, 0xf561), APInt(16, 0xaa0)));
    304   EXPECT_EQ(Wrap.sub(APInt(16, 4)),
    305             ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
    306   EXPECT_EQ(One.sub(APInt(16, 4)),
    307             ConstantRange(APInt(16, 0x6)));
    308 }
    309 
    310 TEST_F(ConstantRangeTest, Multiply) {
    311   EXPECT_EQ(Full.multiply(Full), Full);
    312   EXPECT_EQ(Full.multiply(Empty), Empty);
    313   EXPECT_EQ(Full.multiply(One), Full);
    314   EXPECT_EQ(Full.multiply(Some), Full);
    315   EXPECT_EQ(Full.multiply(Wrap), Full);
    316   EXPECT_EQ(Empty.multiply(Empty), Empty);
    317   EXPECT_EQ(Empty.multiply(One), Empty);
    318   EXPECT_EQ(Empty.multiply(Some), Empty);
    319   EXPECT_EQ(Empty.multiply(Wrap), Empty);
    320   EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa),
    321                                              APInt(16, 0xa*0xa + 1)));
    322   EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa),
    323                                               APInt(16, 0xa*0xaa9 + 1)));
    324   EXPECT_EQ(One.multiply(Wrap), Full);
    325   EXPECT_EQ(Some.multiply(Some), Full);
    326   EXPECT_EQ(Some.multiply(Wrap), Full);
    327   EXPECT_EQ(Wrap.multiply(Wrap), Full);
    328 
    329   // http://llvm.org/PR4545
    330   EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
    331                 ConstantRange(APInt(4, 6), APInt(4, 2))),
    332             ConstantRange(4, /*isFullSet=*/true));
    333 }
    334 
    335 TEST_F(ConstantRangeTest, UMax) {
    336   EXPECT_EQ(Full.umax(Full), Full);
    337   EXPECT_EQ(Full.umax(Empty), Empty);
    338   EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
    339   EXPECT_EQ(Full.umax(Wrap), Full);
    340   EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
    341   EXPECT_EQ(Empty.umax(Empty), Empty);
    342   EXPECT_EQ(Empty.umax(Some), Empty);
    343   EXPECT_EQ(Empty.umax(Wrap), Empty);
    344   EXPECT_EQ(Empty.umax(One), Empty);
    345   EXPECT_EQ(Some.umax(Some), Some);
    346   EXPECT_EQ(Some.umax(Wrap), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
    347   EXPECT_EQ(Some.umax(One), Some);
    348   // TODO: ConstantRange is currently over-conservative here.
    349   EXPECT_EQ(Wrap.umax(Wrap), Full);
    350   EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
    351   EXPECT_EQ(One.umax(One), One);
    352 }
    353 
    354 TEST_F(ConstantRangeTest, SMax) {
    355   EXPECT_EQ(Full.smax(Full), Full);
    356   EXPECT_EQ(Full.smax(Empty), Empty);
    357   EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa),
    358                                            APInt::getSignedMinValue(16)));
    359   EXPECT_EQ(Full.smax(Wrap), Full);
    360   EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa),
    361                                           APInt::getSignedMinValue(16)));
    362   EXPECT_EQ(Empty.smax(Empty), Empty);
    363   EXPECT_EQ(Empty.smax(Some), Empty);
    364   EXPECT_EQ(Empty.smax(Wrap), Empty);
    365   EXPECT_EQ(Empty.smax(One), Empty);
    366   EXPECT_EQ(Some.smax(Some), Some);
    367   EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
    368                                            APInt(16, (uint64_t)INT16_MIN)));
    369   EXPECT_EQ(Some.smax(One), Some);
    370   EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
    371                                           APInt(16, (uint64_t)INT16_MIN)));
    372   EXPECT_EQ(One.smax(One), One);
    373 }
    374 
    375 TEST_F(ConstantRangeTest, UDiv) {
    376   EXPECT_EQ(Full.udiv(Full), Full);
    377   EXPECT_EQ(Full.udiv(Empty), Empty);
    378   EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0),
    379                                           APInt(16, 0xffff / 0xa + 1)));
    380   EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0),
    381                                            APInt(16, 0xffff / 0xa + 1)));
    382   EXPECT_EQ(Full.udiv(Wrap), Full);
    383   EXPECT_EQ(Empty.udiv(Empty), Empty);
    384   EXPECT_EQ(Empty.udiv(One), Empty);
    385   EXPECT_EQ(Empty.udiv(Some), Empty);
    386   EXPECT_EQ(Empty.udiv(Wrap), Empty);
    387   EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1)));
    388   EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2)));
    389   EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
    390   EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
    391   EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
    392   EXPECT_EQ(Wrap.udiv(Wrap), Full);
    393 }
    394 
    395 TEST_F(ConstantRangeTest, Shl) {
    396   EXPECT_EQ(Full.shl(Full), Full);
    397   EXPECT_EQ(Full.shl(Empty), Empty);
    398   EXPECT_EQ(Full.shl(One), Full);    // TODO: [0, (-1 << 0xa) + 1)
    399   EXPECT_EQ(Full.shl(Some), Full);   // TODO: [0, (-1 << 0xa) + 1)
    400   EXPECT_EQ(Full.shl(Wrap), Full);
    401   EXPECT_EQ(Empty.shl(Empty), Empty);
    402   EXPECT_EQ(Empty.shl(One), Empty);
    403   EXPECT_EQ(Empty.shl(Some), Empty);
    404   EXPECT_EQ(Empty.shl(Wrap), Empty);
    405   EXPECT_EQ(One.shl(One), ConstantRange(APInt(16, 0xa << 0xa),
    406                                         APInt(16, (0xa << 0xa) + 1)));
    407   EXPECT_EQ(One.shl(Some), Full);    // TODO: [0xa << 0xa, 0)
    408   EXPECT_EQ(One.shl(Wrap), Full);    // TODO: [0xa, 0xa << 14 + 1)
    409   EXPECT_EQ(Some.shl(Some), Full);   // TODO: [0xa << 0xa, 0xfc01)
    410   EXPECT_EQ(Some.shl(Wrap), Full);   // TODO: [0xa, 0x7ff << 0x5 + 1)
    411   EXPECT_EQ(Wrap.shl(Wrap), Full);
    412 }
    413 
    414 TEST_F(ConstantRangeTest, Lshr) {
    415   EXPECT_EQ(Full.lshr(Full), Full);
    416   EXPECT_EQ(Full.lshr(Empty), Empty);
    417   EXPECT_EQ(Full.lshr(One), ConstantRange(APInt(16, 0),
    418                                           APInt(16, (0xffff >> 0xa) + 1)));
    419   EXPECT_EQ(Full.lshr(Some), ConstantRange(APInt(16, 0),
    420                                            APInt(16, (0xffff >> 0xa) + 1)));
    421   EXPECT_EQ(Full.lshr(Wrap), Full);
    422   EXPECT_EQ(Empty.lshr(Empty), Empty);
    423   EXPECT_EQ(Empty.lshr(One), Empty);
    424   EXPECT_EQ(Empty.lshr(Some), Empty);
    425   EXPECT_EQ(Empty.lshr(Wrap), Empty);
    426   EXPECT_EQ(One.lshr(One), ConstantRange(APInt(16, 0)));
    427   EXPECT_EQ(One.lshr(Some), ConstantRange(APInt(16, 0)));
    428   EXPECT_EQ(One.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
    429   EXPECT_EQ(Some.lshr(Some), ConstantRange(APInt(16, 0),
    430                                            APInt(16, (0xaaa >> 0xa) + 1)));
    431   EXPECT_EQ(Some.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
    432   EXPECT_EQ(Wrap.lshr(Wrap), Full);
    433 }
    434 
    435 TEST(ConstantRange, MakeICmpRegion) {
    436   // PR8250
    437   ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32));
    438   EXPECT_TRUE(ConstantRange::makeICmpRegion(ICmpInst::ICMP_SGT,
    439                                             SMax).isEmptySet());
    440 }
    441 
    442 }  // anonymous namespace
    443