[PATCH] D64142: [SLP] try to create vector loads from bitcasted scalar pointers

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 3 11:42:56 PDT 2019


spatel added a comment.

In D64142#1568892 <https://reviews.llvm.org/D64142#1568892>, @vporpo wrote:

> I am probably missing out something, but isn't this profitable only if we have more than one of these scalar loads extracting from the same vector load?


It's almost certainly more profitable with >1 load, but that's not a requirement for profitability from what I can tell. Here's a more realistic example for the single load case:

  define <2 x i64> @load_splat(<4 x float>* dereferenceable(16) %p, <2 x i64> %y) {
    %bc = bitcast <4 x float>* %p to i64*
    %ld = load i64, i64* %bc, align 16
    %ins = insertelement <2 x i64> undef, i64 %ld, i32 0
    %splat = shufflevector <2 x i64> %ins, <2 x i64> undef, <2 x i32> zeroinitializer
    %add  = add <2 x i64> %splat, %y
    ret <2 x i64> %add
  }

Current codegen for an x86 SSE target:

  movq	(%rdi), %xmm1           # xmm1 = mem[0],zero
  pshufd	$68, %xmm1, %xmm1       # xmm1 = xmm1[0,1,0,1]
  paddq	%xmm1, %xmm0

With this patch, the IR is reduced to:

  $ ./opt load-bitcast-vec.ll -S -mtriple=x86_64-- -slp-vectorizer -instcombine
  define <2 x i64> @larger_scalar(<4 x float>* dereferenceable(16) %p, <2 x i64> %y) {
    %1 = bitcast <4 x float>* %p to <2 x i64>*
    %2 = load <2 x i64>, <2 x i64>* %1, align 16
    %splat = shufflevector <2 x i64> %2, <2 x i64> undef, <2 x i32> zeroinitializer
    %add = add <2 x i64> %splat, %y
    ret <2 x i64> %add
  }

And codegen improves by folding the load:

  pshufd	$68, (%rdi), %xmm1      # xmm1 = mem[0,1,0,1]
  paddq	%xmm1, %xmm0

> Perhaps we could use these scalar loads as seeds and do short top-down SLP?
>  Also isn't it better to run this after vectorizeStoreChains() ?

I don't have enough familiarity with SLP to know how to best fit these pieces together, but those seem like reasonable ideas. I was only trying to assess viability with this initial proposal - and not break anything. :)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64142/new/

https://reviews.llvm.org/D64142





More information about the llvm-commits mailing list