[PATCH] D152276: [DAGCombine] Fold (store (insert_elt (load p)) x p) -> (store x)

Luke Lau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 08:01:17 PDT 2023


luke created this revision.
luke added reviewers: craig.topper, frasercrmck, reames, dmgreen, RKSimon, foad.
Herald added subscribers: asb, pmatos, StephenFan, luismarques, apazos, sameer.abuasal, steven.zhang, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, atanasyan, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson, sdardis.
Herald added a project: All.
luke requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, MaskRay.
Herald added a project: LLVM.

If we have a store of a load with no other uses in between it, it's
considered dead and is removed. So sometimes when legalizing a fixed
length vector store of an insert, we end up producing better code
through scalarization than without.
An example is the follow below:

  %a = load <4 x i64>, ptr %x
  %b = insertelement <4 x i64> %a, i64 %y, i32 2
  store <4 x i64> %b, ptr %x

If this is scalarized, then DAGCombine successfully removes 3 of the 4
stores which are considered dead, and on RISC-V we get:

  sd a1, 16(a0)

However if we make the vector type legal (-mattr=+v), then we lose the
optimisation because we don't scalarize it.

This patch attempts to recover the optimisation for vectors by
identifying patterns where we store a load with a single insert
inbetween, replacing it with a scalar store of the inserted element.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152276

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AArch64/vector-insert-shuffle-cycle.ll
  llvm/test/CodeGen/ARM/vector-DAGCombine.ll
  llvm/test/CodeGen/Mips/msa/basic_operations.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert.ll
  llvm/test/CodeGen/X86/fold-load-vec.ll
  llvm/test/CodeGen/X86/pr47874.ll
  llvm/test/CodeGen/X86/pr59980.ll
  llvm/test/CodeGen/X86/vec_insert-mmx.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152276.528868.patch
Type: text/x-patch
Size: 31984 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230606/d6955a16/attachment.bin>


More information about the llvm-commits mailing list