[LSR] Check SCEV on isZero() after extend. PR40514
authorMax Kazantsev <max.kazantsev@azul.com>
Tue, 5 Feb 2019 04:30:37 +0000 (04:30 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Tue, 5 Feb 2019 04:30:37 +0000 (04:30 +0000)
commitd5e595b7a6168f22cba123ce7d66e3f69e5b7cb4
treebfc31975e8dd289596bed298ad93930d3a2f5e8b
parentb0bf530fb5f1483ebf3d45c262404133eb6ad539
[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
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/test/Transforms/LoopStrengthReduce/X86/pr40514.ll [new file with mode: 0644]