[ARM] Simplify address calculation for NEON load/store
authorAndrew Savonichev <andrew.savonichev@gmail.com>
Wed, 8 Sep 2021 15:19:57 +0000 (18:19 +0300)
committerAndrew Savonichev <andrew.savonichev@gmail.com>
Thu, 14 Oct 2021 12:23:10 +0000 (15:23 +0300)
commitdc8a41de34933bc10c4d5d89c539dd0dc80d59cc
treed525552ae2f995101245045233a367c53f1f224a
parent88487662f7c245419e00672c42cb5adc749c1ba3
[ARM] Simplify address calculation for NEON load/store

The patch attempts to optimize a sequence of SIMD loads from the same
base pointer:

    %0 = gep float*, float* base, i32 4
    %1 = bitcast float* %0 to <4 x float>*
    %2 = load <4 x float>, <4 x float>* %1
    ...
    %n1 = gep float*, float* base, i32 N
    %n2 = bitcast float* %n1 to <4 x float>*
    %n3 = load <4 x float>, <4 x float>* %n2

For AArch64 the compiler generates a sequence of LDR Qt, [Xn, #16].
However, 32-bit NEON VLD1/VST1 lack the [Wn, #imm] addressing mode, so
the address is computed before every ld/st instruction:

    add r2, r0, #32
    add r0, r0, #16
    vld1.32 {d18, d19}, [r2]
    vld1.32 {d22, d23}, [r0]

This can be improved by computing address for the first load, and then
using a post-indexed form of VLD1/VST1 to load the rest:

    add r0, r0, #16
    vld1.32 {d18, d19}, [r0]!
    vld1.32 {d22, d23}, [r0]

In order to do that, the patch adds more patterns to DAGCombine:

  - (load (add ptr inc1)) and (add ptr inc2) are now folded if inc1
    and inc2 are constants.

  - (or ptr inc) is now recognized as a pointer increment if ptr is
    sufficiently aligned.

In addition to that, we now search for all possible base updates and
then pick the best one.

Differential Revision: https://reviews.llvm.org/D108988
12 files changed:
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/test/CodeGen/ARM/alloc-no-stack-realign.ll
llvm/test/CodeGen/ARM/arm-post-indexing-opt.ll [new file with mode: 0644]
llvm/test/CodeGen/ARM/fp16-vector-argument.ll
llvm/test/CodeGen/ARM/large-vector.ll
llvm/test/CodeGen/ARM/memcpy-inline.ll
llvm/test/CodeGen/ARM/memset-align.ll
llvm/test/CodeGen/ARM/misched-fusion-aes.ll
llvm/test/CodeGen/ARM/vector-load.ll
llvm/test/CodeGen/ARM/vext.ll
llvm/test/CodeGen/ARM/vselect_imax.ll
llvm/test/Transforms/LoopStrengthReduce/ARM/ivchain-ARM.ll