forked from OSchip/llvm-project
[SCEV] Remove extra APInt copies from getRangeForAffineARHelper.
This changes one parameter to be a const APInt& since we only read from it. Use std::move on local APInts once they are no longer needed so we can reuse their allocations. Lastly, use operator+=(uint64_t) instead of adding 1 to an APInt twice creating a new APInt each time. llvm-svn: 302335
This commit is contained in:
parent
69f1af29fb
commit
6c5e22a4b8
|
@ -4843,7 +4843,7 @@ ScalarEvolution::getRange(const SCEV *S,
|
||||||
// argument defines if we treat Step as signed or unsigned.
|
// argument defines if we treat Step as signed or unsigned.
|
||||||
static ConstantRange getRangeForAffineARHelper(APInt Step,
|
static ConstantRange getRangeForAffineARHelper(APInt Step,
|
||||||
ConstantRange StartRange,
|
ConstantRange StartRange,
|
||||||
APInt MaxBECount,
|
const APInt &MaxBECount,
|
||||||
unsigned BitWidth, bool Signed) {
|
unsigned BitWidth, bool Signed) {
|
||||||
// If either Step or MaxBECount is 0, then the expression won't change, and we
|
// If either Step or MaxBECount is 0, then the expression won't change, and we
|
||||||
// just need to return the initial range.
|
// just need to return the initial range.
|
||||||
|
@ -4882,8 +4882,8 @@ static ConstantRange getRangeForAffineARHelper(APInt Step,
|
||||||
// if the expression is decreasing and will be increased by Offset otherwise.
|
// if the expression is decreasing and will be increased by Offset otherwise.
|
||||||
APInt StartLower = StartRange.getLower();
|
APInt StartLower = StartRange.getLower();
|
||||||
APInt StartUpper = StartRange.getUpper() - 1;
|
APInt StartUpper = StartRange.getUpper() - 1;
|
||||||
APInt MovedBoundary =
|
APInt MovedBoundary = Descending ? (StartLower - std::move(Offset))
|
||||||
Descending ? (StartLower - Offset) : (StartUpper + Offset);
|
: (StartUpper + std::move(Offset));
|
||||||
|
|
||||||
// It's possible that the new minimum/maximum value will fall into the initial
|
// It's possible that the new minimum/maximum value will fall into the initial
|
||||||
// range (due to wrap around). This means that the expression can take any
|
// range (due to wrap around). This means that the expression can take any
|
||||||
|
@ -4891,21 +4891,18 @@ static ConstantRange getRangeForAffineARHelper(APInt Step,
|
||||||
if (StartRange.contains(MovedBoundary))
|
if (StartRange.contains(MovedBoundary))
|
||||||
return ConstantRange(BitWidth, /* isFullSet = */ true);
|
return ConstantRange(BitWidth, /* isFullSet = */ true);
|
||||||
|
|
||||||
APInt NewLower, NewUpper;
|
APInt NewLower =
|
||||||
if (Descending) {
|
Descending ? std::move(MovedBoundary) : std::move(StartLower);
|
||||||
NewLower = MovedBoundary;
|
APInt NewUpper =
|
||||||
NewUpper = StartUpper;
|
Descending ? std::move(StartUpper) : std::move(MovedBoundary);
|
||||||
} else {
|
NewUpper += 1;
|
||||||
NewLower = StartLower;
|
|
||||||
NewUpper = MovedBoundary;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we end up with full range, return a proper full range.
|
// If we end up with full range, return a proper full range.
|
||||||
if (NewLower == NewUpper + 1)
|
if (NewLower == NewUpper)
|
||||||
return ConstantRange(BitWidth, /* isFullSet = */ true);
|
return ConstantRange(BitWidth, /* isFullSet = */ true);
|
||||||
|
|
||||||
// No overflow detected, return [StartLower, StartUpper + Offset + 1) range.
|
// No overflow detected, return [StartLower, StartUpper + Offset + 1) range.
|
||||||
return ConstantRange(NewLower, NewUpper + 1);
|
return ConstantRange(std::move(NewLower), std::move(NewUpper));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantRange ScalarEvolution::getRangeForAffineAR(const SCEV *Start,
|
ConstantRange ScalarEvolution::getRangeForAffineAR(const SCEV *Start,
|
||||||
|
|
Loading…
Reference in New Issue