[PATCH] D45522: [PowerPC] fix incorrect vectorization of abs() on POWER9

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 11 08:33:39 PDT 2018


inouehrs created this revision.
inouehrs added reviewers: hfinkel, echristo, kbarton, sfertile, nemanjai, syzaara, lei.

Vectorized loops with abs() returns incorrect results on POWER9. This patch fixes it.
For example the following code returns negative result if input values are negative though it sums up the absolute value of the inputs. This problem causes test failures for libvpx.

  int vpx_satd_c(const int16_t *coeff, int length) {
    int satd = 0;
    for (int i = 0; i < length; ++i) satd += abs(coeff[i]);
    return satd;
  }

For vector absolute and vector absolute difference on POWER9, LLVM generates VABSDUW (Vector Absolute Difference Unsigned Word) instruction or variants.
Since these instructions are for unsigned integers, we need adjustment for signed integers.
For abs(sub(a, b)), we generate VABSDUW(a+0x80000000, b+0x80000000). Otherwise, abs(sub(-1, 0)) returns 0xFFFFFFFF(=-1) instead of 1. For abs(a), we generate VABSDUW(a+0x80000000, 0x80000000).


https://reviews.llvm.org/D45522

Files:
  lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  lib/Target/PowerPC/PPCInstrAltivec.td
  test/CodeGen/PowerPC/ppc64-P9-vabsd.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45522.142019.patch
Type: text/x-patch
Size: 7571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180411/024c051e/attachment.bin>


More information about the llvm-commits mailing list