[SelectionDAG] Extend FoldConstantVectorArithmetic to SPLAT_VECTOR
authorFraser Cormack <fraser@codeplay.com>
Thu, 27 May 2021 12:45:23 +0000 (13:45 +0100)
committerFraser Cormack <fraser@codeplay.com>
Fri, 4 Jun 2021 08:53:15 +0000 (09:53 +0100)
commitaec9cbbeb863dbd3ea362f99eb8b84dfbdb568a2
treeaaf45d25df3c9760f15e366c439b5325fd0447c2
parent67b1c37d9fd1283d7015edb9c0fecb24362751f4
[SelectionDAG] Extend FoldConstantVectorArithmetic to SPLAT_VECTOR

This patch extends the SelectionDAG's ability to constant-fold vector
arithmetic to include support for SPLAT_VECTOR. This is not only for
scalable-vector types but also for fixed-length vector types, which
helps Hexagon in a couple of cases.

The original RISC-V test case was in fact an infinite DAGCombine loop.
The pattern `and (truncate v1), (truncate v2)` can be combined to
`truncate (and v1, v2)` but the truncate can similarly be combined back
to `truncate (and v1, v2)` (but, crucially, only when one of `v1` or
`v2` is a constant vector).

It wasn't exposed in on fixed-length types because a TRUNCATE of a
constant BUILD_VECTOR was folded into the BUILD_VECTOR itself, whereas
this did not happen for the equivalent (scalable-vector) SPLAT_VECTOR.

Reviewed By: RKSimon, craig.topper

Differential Revision: https://reviews.llvm.org/D103246
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/AArch64/sve-expand-div.ll
llvm/test/CodeGen/Hexagon/isel-memory-vNi1.ll
llvm/test/CodeGen/RISCV/rvv/constant-folding.ll [new file with mode: 0644]
llvm/test/CodeGen/RISCV/rvv/setcc-integer-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vdivu-sdnode-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vdivu-sdnode-rv64.ll
llvm/test/CodeGen/RISCV/rvv/vremu-sdnode-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vremu-sdnode-rv64.ll