diff options
author | Philip Reames <preames@rivosinc.com> | 2023-11-03 10:21:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 10:21:30 -0700 |
commit | 1ffea97ffdbe4148db7c6db4638d2ec56234c502 (patch) | |
tree | b4e3daeecbb2182a551eb622e68089beace080ce /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 7ca0f4418a6d385e07d9aff42865c34d3dc2adf7 (diff) | |
download | llvm-1ffea97ffdbe4148db7c6db4638d2ec56234c502.zip llvm-1ffea97ffdbe4148db7c6db4638d2ec56234c502.tar.gz llvm-1ffea97ffdbe4148db7c6db4638d2ec56234c502.tar.bz2 |
[indvars] Support known positive extends in getExtendedOperandRecurrence (#70990)
IndVars has the existing notion of a narrow definition which is known to
positive and thus both sign and zero extension kinds are actually the
same operations. There's existing logic for forming a SCEV based on the
extension kind and the no-wrap flags. This change extends that logic to
form the opposite extension kind for a positive def if doing so is
allowed by the flags. Note that we already do something analogous for
the getWideRecurrence case as well.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index de2556f..9b91d74 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1393,7 +1393,22 @@ WidenIV::getExtendedOperandRecurrence(WidenIV::NarrowIVDefUse DU) { else if (ExtKind == ExtendKind::Zero && OBO->hasNoUnsignedWrap()) ExtendOperExpr = SE->getZeroExtendExpr( SE->getSCEV(DU.NarrowUse->getOperand(ExtendOperIdx)), WideType); - else + else if (DU.NeverNegative) { + // For a non-negative NarrowDef, we can choose either type of + // extension. We want to use the current extend kind if legal + // (see above), and we only hit this code if we need to check + // the opposite case. + if (OBO->hasNoSignedWrap()) { + ExtKind = ExtendKind::Sign; + ExtendOperExpr = SE->getSignExtendExpr( + SE->getSCEV(DU.NarrowUse->getOperand(ExtendOperIdx)), WideType); + } else if (OBO->hasNoUnsignedWrap()) { + ExtKind = ExtendKind::Zero; + ExtendOperExpr = SE->getZeroExtendExpr( + SE->getSCEV(DU.NarrowUse->getOperand(ExtendOperIdx)), WideType); + } else + return {nullptr, ExtendKind::Unknown}; + } else return {nullptr, ExtendKind::Unknown}; // When creating this SCEV expr, don't apply the current operations NSW or NUW |