[PATCH] D130839: [DAG] FoldConstantArithmetic - add initial support for undef elements in bitcasted binop constant folding

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 31 06:21:51 PDT 2022


RKSimon created this revision.
RKSimon added reviewers: craig.topper, dmgreen, efriedma, spatel, xiangzhangllvm.
Herald added subscribers: luke957, StephenFan, frasercrmck, luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
RKSimon requested review of this revision.
Herald added subscribers: pcwang-thead, MaskRay.
Herald added a project: LLVM.

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 materializes it instead?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130839

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130839.448854.patch
Type: text/x-patch
Size: 5938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220731/f4b5da79/attachment.bin>


More information about the llvm-commits mailing list