mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-20 10:24:12 +00:00
LoopVectorizer: Truncate i64 trip counts of i32 phis if necessary
In signed arithmetic we could end up with an i64 trip count for an i32 phi. Because it is signed arithmetic we know that this is only defined if the i32 does not wrap. It is therefore safe to truncate the i64 trip count to a i32 value. Fixes PR18049. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1537,6 +1537,15 @@ InnerLoopVectorizer::createEmptyLoop(LoopVectorizationLegality *Legal) {
|
||||
const SCEV *ExitCount = SE->getBackedgeTakenCount(OrigLoop);
|
||||
assert(ExitCount != SE->getCouldNotCompute() && "Invalid loop count");
|
||||
|
||||
// The exit count might have the type of i64 while the phi is i32. This can
|
||||
// happen if we have an induction variable that is sign extended before the
|
||||
// compare. The only way that we get a backedge taken count is that the
|
||||
// induction variable was signed and as such will not overflow. In such a case
|
||||
// truncation is legal.
|
||||
if (ExitCount->getType()->getPrimitiveSizeInBits() >
|
||||
IdxTy->getPrimitiveSizeInBits())
|
||||
ExitCount = SE->getTruncateOrNoop(ExitCount, IdxTy);
|
||||
|
||||
ExitCount = SE->getNoopOrZeroExtend(ExitCount, IdxTy);
|
||||
// Get the total trip count from the count by adding 1.
|
||||
ExitCount = SE->getAddExpr(ExitCount,
|
||||
|
Reference in New Issue
Block a user