llvm.org GIT mirror llvm / 646ca92
Fix handling of max and full set. A full set is a constant range that represents any number. If you take the umax of that and [5, 10) you end up with [5, INT_MAX] because the values less than 5 would be umax's against a value which is at least 5. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75372 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 10 years ago
2 changed file(s) with 8 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
560560 // smax(X_smax, Y_smax))
561561 if (isEmptySet() || Other.isEmptySet())
562562 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
563 if (isFullSet() || Other.isFullSet())
564 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
565563 APInt NewL = APIntOps::smax(getSignedMin(), Other.getSignedMin());
566564 APInt NewU = APIntOps::smax(getSignedMax(), Other.getSignedMax()) + 1;
567565 if (NewU == NewL)
575573 // umax(X_umax, Y_umax))
576574 if (isEmptySet() || Other.isEmptySet())
577575 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
578 if (isFullSet() || Other.isFullSet())
579 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
580576 APInt NewL = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin());
581577 APInt NewU = APIntOps::umax(getUnsignedMax(), Other.getUnsignedMax()) + 1;
582578 if (NewU == NewL)
183183 APInt(Some.getUpper()).sext(20)));
184184 EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20),
185185 APInt(Wrap.getUpper()).sext(20)));
186
187186 }
188187
189188 TEST_F(ConstantRangeTest, IntersectWith) {
284283 TEST_F(ConstantRangeTest, UMax) {
285284 EXPECT_TRUE(Full.umax(Full).isFullSet());
286285 EXPECT_TRUE(Full.umax(Empty).isEmptySet());
287 EXPECT_TRUE(Full.umax(Some).isFullSet());
286 EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
288287 EXPECT_TRUE(Full.umax(Wrap).isFullSet());
289 EXPECT_TRUE(Full.umax(One).isFullSet());
288 EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
290289 EXPECT_EQ(Empty.umax(Empty), Empty);
291290 EXPECT_EQ(Empty.umax(Some), Empty);
292291 EXPECT_EQ(Empty.umax(Wrap), Empty);
303302 TEST_F(ConstantRangeTest, SMax) {
304303 EXPECT_TRUE(Full.smax(Full).isFullSet());
305304 EXPECT_TRUE(Full.smax(Empty).isEmptySet());
306 EXPECT_TRUE(Full.smax(Some).isFullSet());
305 EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa),
306 APInt::getSignedMinValue(16)));
307307 EXPECT_TRUE(Full.smax(Wrap).isFullSet());
308 EXPECT_TRUE(Full.smax(One).isFullSet());
308 EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa),
309 APInt::getSignedMinValue(16)));
309310 EXPECT_EQ(Empty.smax(Empty), Empty);
310311 EXPECT_EQ(Empty.smax(Some), Empty);
311312 EXPECT_EQ(Empty.smax(Wrap), Empty);
312313 EXPECT_EQ(Empty.smax(One), Empty);
313314 EXPECT_EQ(Some.smax(Some), Some);
314315 EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa),
315 APInt(16, INT16_MIN)));
316 APInt(16, INT16_MIN)));
316317 EXPECT_EQ(Some.smax(One), Some);
317318 EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
318 APInt(16, INT16_MIN)));
319 APInt(16, INT16_MIN)));
319320 EXPECT_EQ(One.smax(One), One);
320321 }
321322