llvm.org GIT mirror llvm / 2ff893f
Implement ConstantRange::multiply based on the code in LoopVR. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75410 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 10 years ago
2 changed file(s) with 19 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
549549
550550 ConstantRange
551551 ConstantRange::multiply(const ConstantRange &Other) const {
552 // TODO: Implement multiply.
553 return ConstantRange(getBitWidth(),
554 !(isEmptySet() || Other.isEmptySet()));
552 if (isEmptySet() || Other.isEmptySet())
553 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
554 if (isFullSet() || Other.isFullSet())
555 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
556
557 ConstantRange this_zext = zeroExtend(getBitWidth() * 2);
558 ConstantRange Other_zext = Other.zeroExtend(getBitWidth() * 2);
559
560 ConstantRange Result_zext = ConstantRange(
561 this_zext.getLower() * Other_zext.getLower(),
562 ((this_zext.getUpper()-1) * (Other_zext.getUpper()-1)) + 1);
563
564 return Result_zext.truncate(getBitWidth());
555565 }
556566
557567 ConstantRange
266266 EXPECT_EQ(Empty.multiply(One), Empty);
267267 EXPECT_EQ(Empty.multiply(Some), Empty);
268268 EXPECT_EQ(Empty.multiply(Wrap), Empty);
269 // TODO: ConstantRange is currently over-conservative here.
270 EXPECT_EQ(One.multiply(One), Full);
271 // TODO: ConstantRange is currently over-conservative here.
272 EXPECT_EQ(One.multiply(Some), Full);
273 // TODO: ConstantRange is currently over-conservative here.
274 EXPECT_EQ(One.multiply(Wrap), Full);
275 // TODO: ConstantRange is currently over-conservative here.
276 EXPECT_EQ(Some.multiply(Some), Full);
277 // TODO: ConstantRange is currently over-conservative here.
269 EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa),
270 APInt(16, 0xa*0xa + 1)));
271 EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa),
272 APInt(16, 0xa*0xaa9 + 1)));
273 EXPECT_TRUE(One.multiply(Wrap).isFullSet());
274 EXPECT_TRUE(Some.multiply(Some).isFullSet());
278275 EXPECT_EQ(Some.multiply(Wrap), Full);
279 // TODO: ConstantRange is currently over-conservative here.
280276 EXPECT_EQ(Wrap.multiply(Wrap), Full);
281277 }
282278