[PATCH] D143267: [LoopVectorize] Use DataLayout::getIndexType instead of i32 for non-constant GEP indices.

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 07:02:37 PST 2023


sdesmalen created this revision.
sdesmalen added reviewers: paulwalker-arm, MattDevereau, fhahn, david-arm.
Herald added subscribers: luke, shiva0217, StephenFan, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
Herald added a project: All.
sdesmalen requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, alextsao1999, MaskRay.
Herald added a project: LLVM.

This is specifically relevant for loops that vectorize using a scalable VF,
where the code results in:

  %vscale = call i32 llvm.vscale.i32()
  %vf.part1 = mul i32 %vscale, 4
  %gep = getelementptr  ..., i32 %vf.part1

Which InstCombine then changes into:

  %vscale = call i32 llvm.vscale.i32()
  %vf.part1 = mul i32 %vscale, 4
  %vf.part1.zext = sext i32 %vf.part1 to i64
  %gep = getelementptr  ..., i32 %vf.part1.zext

D143016 <https://reviews.llvm.org/D143016> tried to remove these extends, but that only works when
the call to llvm.vscale.i32() has a single use. After doing any
kind of CSE on these calls the combine no longer kicks in.

It seems more sensible to ask DataLayout what type to use, rather
than relying on InstCombine to insert the extend and hoping it can
fold it away.

I've only changed this for indices that are not constant, because
I vaguely remember there was a reason for sticking with i32. It
would also mean patching up loads more tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143267

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/AArch64/sve-epilog-vect-inloop-reductions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-epilog-vect-reductions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-epilog-vect-strict-reductions.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-epilog-vect.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-fneg.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-gather-scatter.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-live-out-pointer-induction.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-runtime-check-size-based-threshold.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-tail-folding-unroll.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-vector-reverse.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
  llvm/test/Transforms/LoopVectorize/RISCV/divrem.ll
  llvm/test/Transforms/LoopVectorize/RISCV/inloop-reduction.ll
  llvm/test/Transforms/LoopVectorize/RISCV/mask-index-type.ll
  llvm/test/Transforms/LoopVectorize/RISCV/scalable-basics.ll
  llvm/test/Transforms/LoopVectorize/scalable-inductions.ll
  llvm/test/Transforms/LoopVectorize/scalable-loop-unpredicated-body-scalar-tail.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143267.494623.patch
Type: text/x-patch
Size: 105102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230203/451b1e88/attachment.bin>


More information about the llvm-commits mailing list