This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] vectorize Sum of Absolute Difference
AbandonedPublic

Authored by inouehrs on Apr 25 2018, 7:52 PM.

Details

Summary

This patch enables vectorization of Sum of Absolute Difference (SAD), which is already supported in x86 backend.
For example, the following code is compiled with vector max/min and sum-across instructions.

uint8_t *pix1, *pix2;
unsigned i_sum = 0;
for( unsigned x = 0; x < 16; x++ )
  i_sum += abs( pix1[x] - pix2[x] );

To implement this, I moved some helper functions defined in X86TargetLowering into the parent class TargetLowering with minor generalization to reuse them from PPC backend.
Is this an acceptable approach or is it better to implement analysis as DAG combining (and introduce a new Opcode like ISD::SAD)?

This patch supports only ppc64le so far. If accepted, I will add big endian support and also POWER9 new instruction support.

Diff Detail

Event Timeline

inouehrs created this revision.Apr 25 2018, 7:52 PM
RKSimon added a subscriber: RKSimon.
RKSimon added inline comments.
lib/CodeGen/SelectionDAG/TargetLowering.cpp
4362

In a more general setting we probably need to support ABS(SUB(ZEXT(x)), ZEXT(y))) as well

lib/Target/PowerPC/PPCISelLowering.cpp
12110

This (and the comment) needs updating for PPC, maybe merge the 2 ifs to just:

if (VT != MVT::v16i8 && VT != MVT::v8i16)
  return SDValue();
12130

How come PPC doesn't use the ISD::SMAX/SMIN/UMAX/UMIN opcodes? It'd remove a lot of this duplication.

test/CodeGen/PowerPC/ppc64_basicSAD.ll
1

Why not use utils/update_llc_test_checks.py ?

@inouehrs Are you still looking at this at all?

inouehrs abandoned this revision.Sep 29 2018, 9:16 AM

@RKSimon Other colleagues in IBM are working on this and hopefully they will submit a patch separately. So I abandone this.
Thank you so much for your comments.