[LoopVectorize] Fix crash on "getNoopOrZeroExtend cannot truncate!" (PR45259)
authorVedant Kumar <vsk@apple.com>
Mon, 30 Mar 2020 17:02:21 +0000 (10:02 -0700)
committerVedant Kumar <vsk@apple.com>
Mon, 30 Mar 2020 17:14:14 +0000 (10:14 -0700)
commitdcc410b5cf202e354105df431fad62d2f5f7eac7
tree5c5884dd82383da522cb6d47fa0d3c9c39872be8
parent673e81eee4fa3ffa38736f1063e6c4fa2d9278b0
[LoopVectorize] Fix crash on "getNoopOrZeroExtend cannot truncate!" (PR45259)

In InnerLoopVectorizer::getOrCreateTripCount, when the backedge taken
count is a SCEV add expression, its type is defined by the type of the
last operand of the add expression.

In the test case from PR45259, this last operand happens to be a
pointer, which (according to llvm::Type) does not have a primitive size
in bits. In this case, LoopVectorize fails to truncate the SCEV and
crashes as a result.

Uing ScalarEvolution::getTypeSizeInBits makes the truncation work as expected.

https://bugs.llvm.org/show_bug.cgi?id=45259

Differential Revision: https://reviews.llvm.org/D76669
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/pr45259.ll [new file with mode: 0644]