[Constant] Allow ConstantAggregateZero a scalable element count
authorFraser Cormack <fraser@codeplay.com>
Fri, 7 May 2021 16:41:27 +0000 (17:41 +0100)
committerFraser Cormack <fraser@codeplay.com>
Mon, 10 May 2021 12:51:53 +0000 (13:51 +0100)
commit3212a08a8c811441ca68009118758998750ce905
tree663fa0d87994535edcd1d363444767b9d236f067
parentf088af37e6b570dd070ae4e6fc14e22d21cda3be
[Constant] Allow ConstantAggregateZero a scalable element count

A ConstantAggregateZero may be created from a scalable vector type.
However, it still assumed fixed number of elements when queried for
them. This patch changes ConstantAggregateZero to correctly report its
element count.

This change fixes a couple of issues. Firstly, it fixes a crash in
Constant::getUniqueValue when called on a scalable-vector
zeroinitializer constant.

Secondly, it fixes a latent bug in GlobalISel's IRTranslator in which
translating a scalable-vector zeroinitializer would hit the assertion in
ConstantAggregateZero::getNumElements when casting to a FixedVectorType,
rather than reporting an error more gracefully. This is currently
hypothetical as the IRTranslator has deeper issues preventing the use of
scalable vector types.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D102082
llvm/include/llvm/IR/Constants.h
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/IR/Constants.cpp
llvm/test/Transforms/InstCombine/scalable-select.ll [new file with mode: 0644]