[DAG] FoldConstantArithmetic - add initial support for undef elements in bitcasted...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 8 Aug 2022 10:53:56 +0000 (11:53 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 8 Aug 2022 10:53:56 +0000 (11:53 +0100)
commite5e93b6130bde96d7e14851e218c5bf055f8a834
tree298d28ac7a91b8d2c5eda67831e76ad86c01f94e
parentfb10bb0d2c50d1ec2f3cf827d09f18bc54a8097a
[DAG] FoldConstantArithmetic - add initial support for undef elements in bitcasted binop constant folding

FoldConstantArithmetic can fold constant vectors hidden behind bitcasts (e.g. vXi64 -> v2Xi32 on 32-bit platforms), but currently bails if either vector contains undef elements. These undefs can often occur due to SimplifyDemandedBits/VectorElts calls recognising that the upper bits are often unnecessary (e.g. funnel-shift/rotate implicit-modulo and AND masks).

This patch adds a basic 'FoldValueWithUndef' handler that will attempt to constant fold if one or both of the ops are undef - so far this just handles the AND and MUL cases where we always fold to zero.

The RISCV codegen increase is interesting - it looks like the BUILD_VECTOR lowering was loading a constant pool entry but now (with all elements defined constant) it can materialize the constant instead?

Differential Revision: https://reviews.llvm.org/D130839
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/ARM/srem-seteq-illegal-types.ll
llvm/test/CodeGen/RISCV/srem-seteq-illegal-types.ll
llvm/test/CodeGen/Thumb2/srem-seteq-illegal-types.ll
llvm/test/CodeGen/X86/fshl-splat-undef.ll