[Constants] Extend support for scalable-vector splats
authorFraser Cormack <fraser@codeplay.com>
Mon, 31 May 2021 17:31:55 +0000 (18:31 +0100)
committerFraser Cormack <fraser@codeplay.com>
Mon, 7 Jun 2021 13:37:56 +0000 (14:37 +0100)
commitfd3b556958a9deee7ced33ec18b38c030145160b
tree31f97b341f84efd75f609655f50772cc21d54f77
parentd12000ca55d1cc8bc07f75457e3b4efbcd8ff657
[Constants] Extend support for scalable-vector splats

This patch extends the various "isXXX" functions of the `Constant` class
to include scalable-vector splats.

In several "isXXX" functions, code that was separately inspecting
`ConstantVector` and `ConstantDataVector` was unified to use
`getSplatValue`, which already includes support for said splats.

In the varous "isNotXXX" functions, code was added to check whether the
scalar splat value -- if any -- satisfies the predicate.

An extra fix for `isNotMinSignedValue` was included, as it previously
crashed when passed a scalable-vector type because it unconditionally
cast to `FixedVectorType`

These changes address numerous missed optimizations, a compiler crash
mentioned above and -- perhaps most egregiously -- an infinite loop in
InstCombine due to the compiler breaking canonical form when it failed
to pick up on a splat in a select instruction.

Test cases have been added to cover as many of these functions as
possible, though existing coverage is slim; it doesn't appear that there
are any in-tree uses of `Constant::isNegativeZeroValue`, for example.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D103421
llvm/lib/IR/Constants.cpp
llvm/test/Transforms/InstCombine/bitcast.ll
llvm/test/Transforms/InstCombine/div.ll
llvm/test/Transforms/InstCombine/fdiv.ll
llvm/test/Transforms/InstCombine/fmul.ll
llvm/test/Transforms/InstCombine/icmp-vec.ll
llvm/test/Transforms/InstCombine/sub.ll