diff options
| author | Max Kazantsev <max.kazantsev@azul.com> | 2019-02-05 04:30:37 +0000 |
|---|---|---|
| committer | Max Kazantsev <max.kazantsev@azul.com> | 2019-02-05 04:30:37 +0000 |
| commit | d5e595b7a6168f22cba123ce7d66e3f69e5b7cb4 (patch) | |
| tree | bfc31975e8dd289596bed298ad93930d3a2f5e8b /llvm/lib/Transforms | |
| parent | b0bf530fb5f1483ebf3d45c262404133eb6ad539 (diff) | |
| download | bcm5719-llvm-d5e595b7a6168f22cba123ce7d66e3f69e5b7cb4.tar.gz bcm5719-llvm-d5e595b7a6168f22cba123ce7d66e3f69e5b7cb4.zip | |
[LSR] Check SCEV on isZero() after extend. PR40514
When LSR first adds SCEVs to BaseRegs, it only does it if `isZero()` has
returned false. In the end, in invocation of `InsertFormula`, it asserts that
all values there are still not zero constants. However between these two
points, it makes some transformations, in particular extends them to wider
type.
SCEV does not give us guarantee that if `S` is not a constant zero, then
`sext(S)` is also not a constant zero. It might have missed some optimizing
transforms when it was calculating `S` and then made them when it took `sext`.
For example, it may happen if previously optimizing transforms were limited
by depth or somehow else.
This patch adds a bailout when we may end up with a zero SCEV after extension.
Differential Revision: https://reviews.llvm.org/D57565
Reviewed By: samparker
llvm-svn: 353136
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 770e8a5785c..eb6b1f24a7f 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -3967,9 +3967,27 @@ void LSRInstance::GenerateTruncates(LSRUse &LU, unsigned LUIdx, Formula Base) { if (SrcTy != DstTy && TTI.isTruncateFree(SrcTy, DstTy)) { Formula F = Base; - if (F.ScaledReg) F.ScaledReg = SE.getAnyExtendExpr(F.ScaledReg, SrcTy); - for (const SCEV *&BaseReg : F.BaseRegs) - BaseReg = SE.getAnyExtendExpr(BaseReg, SrcTy); + // Sometimes SCEV is able to prove zero during ext transform. It may + // happen if SCEV did not do all possible transforms while creating the + // initial node (maybe due to depth limitations), but it can do them while + // taking ext. + if (F.ScaledReg) { + const SCEV *NewScaledReg = SE.getAnyExtendExpr(F.ScaledReg, SrcTy); + if (NewScaledReg->isZero()) + continue; + F.ScaledReg = NewScaledReg; + } + bool HasZeroBaseReg = false; + for (const SCEV *&BaseReg : F.BaseRegs) { + const SCEV *NewBaseReg = SE.getAnyExtendExpr(BaseReg, SrcTy); + if (NewBaseReg->isZero()) { + HasZeroBaseReg = true; + break; + } + BaseReg = NewBaseReg; + } + if (HasZeroBaseReg) + continue; // TODO: This assumes we've done basic processing on all uses and // have an idea what the register usage is. |

