Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/IR/ConstantRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ ConstantRange ConstantRange::zeroExtend(uint32_t DstTySize) const {
if (isEmptySet()) return getEmpty(DstTySize);

unsigned SrcTySize = getBitWidth();
if (DstTySize == SrcTySize)
return *this;
assert(SrcTySize < DstTySize && "Not a value extension");
if (isFullSet() || isUpperWrapped()) {
// Change into [0, 1 << src bit width)
Expand All @@ -858,6 +860,8 @@ ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
if (isEmptySet()) return getEmpty(DstTySize);

unsigned SrcTySize = getBitWidth();
if (DstTySize == SrcTySize)
return *this;
assert(SrcTySize < DstTySize && "Not a value extension");

// special case: [X, INT_MIN) -- not really wrapping around
Expand All @@ -874,6 +878,8 @@ ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {

ConstantRange ConstantRange::truncate(uint32_t DstTySize,
unsigned NoWrapKind) const {
if (DstTySize == getBitWidth())
return *this;
assert(getBitWidth() > DstTySize && "Not a value truncation");
if (isEmptySet())
return getEmpty(DstTySize);
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Utils/SCCPSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2109,10 +2109,10 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {

ConstantRange Count = getValueState(CountArg)
.asConstantRange(CountArg->getType(), false)
.zextOrTrunc(BitWidth);
.zeroExtend(BitWidth);
ConstantRange MaxLanes = getValueState(VF)
.asConstantRange(VF->getType(), false)
.zextOrTrunc(BitWidth);
.zeroExtend(BitWidth);
if (Scalable)
MaxLanes =
MaxLanes.multiply(getVScaleRange(II->getFunction(), BitWidth));
Expand All @@ -2126,7 +2126,7 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
if (Count.icmp(CmpInst::ICMP_ULE, MaxLanes))
Result = Count;

Result = Result.zextOrTrunc(II->getType()->getScalarSizeInBits());
Result = Result.truncate(II->getType()->getScalarSizeInBits());
return (void)mergeInValue(ValueState[II], II,
ValueLatticeElement::getRange(Result));
}
Expand Down
9 changes: 9 additions & 0 deletions llvm/unittests/IR/ConstantRangeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ TEST_F(ConstantRangeTest, Trunc) {
// 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)));

ConstantRange Nop = Full.truncate(Full.getBitWidth());
EXPECT_EQ(Full, Nop);
}

TEST_F(ConstantRangeTest, TruncNuw) {
Expand Down Expand Up @@ -527,6 +530,9 @@ TEST_F(ConstantRangeTest, ZExt) {
// 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)));

ConstantRange Nop = Full.zeroExtend(Full.getBitWidth());
EXPECT_EQ(Full, Nop);
}

TEST_F(ConstantRangeTest, SExt) {
Expand All @@ -550,6 +556,9 @@ TEST_F(ConstantRangeTest, SExt) {

EXPECT_EQ(ConstantRange(APInt(16, 0x0200), APInt(16, 0x8000)).signExtend(19),
ConstantRange(APInt(19, 0x0200), APInt(19, 0x8000)));

ConstantRange Nop = Full.signExtend(Full.getBitWidth());
EXPECT_EQ(Full, Nop);
}

TEST_F(ConstantRangeTest, IntersectWith) {
Expand Down
Loading