1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

make ConstantRange::signExtend() optimal

the case [x, INT_MIN) was not handled optimally

llvm-svn: 193694
This commit is contained in:
Nuno Lopes 2013-10-30 15:36:50 +00:00
parent a305fb792d
commit 79e69672f4
2 changed files with 8 additions and 0 deletions

View File

@ -445,6 +445,11 @@ ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
unsigned SrcTySize = getBitWidth(); unsigned SrcTySize = getBitWidth();
assert(SrcTySize < DstTySize && "Not a value extension"); assert(SrcTySize < DstTySize && "Not a value extension");
// special case: [X, INT_MIN) -- not really wrapping around
if (Upper == APInt::getHighBitsSet(SrcTySize, 1))
return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize));
if (isFullSet() || isSignWrappedSet()) { if (isFullSet() || isSignWrappedSet()) {
return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1), return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 1); APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 1);

View File

@ -216,6 +216,9 @@ TEST_F(ConstantRangeTest, SExt) {
EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16), EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16),
ConstantRange(APInt(16, -128), APInt(16, 128))); ConstantRange(APInt(16, -128), APInt(16, 128)));
EXPECT_EQ(ConstantRange(APInt(16, 0x0200), APInt(16, 0x8000)).signExtend(19),
ConstantRange(APInt(19, 0x0200), APInt(19, 0x8000)));
} }
TEST_F(ConstantRangeTest, IntersectWith) { TEST_F(ConstantRangeTest, IntersectWith) {