[PATCH] D100370: [AArch64][SVE] Fix bug in lowering of fixed-length integer vector divides

Joe Ellis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 13 01:56:05 PDT 2021


joechrisellis created this revision.
joechrisellis added reviewers: paulwalker-arm, peterwaller-arm, DavidTruby, sdesmalen, kmclaughlin.
Herald added subscribers: psnobl, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
joechrisellis requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The function AArch64TargetLowering::LowerFixedLengthVectorIntDivideToSVE
previously assumed the operands were full vectors, but this is not
always true. This function would produce bogus if the division operands
are not full vectors, resulting in miscompiles when dividing 8-bit or
16-bit vectors.

The fix is to perform an extend + div + truncate for non-full vectors,
instead of the usual unpacking and unzipping logic. This is an additive
change which reduces the non-full integer vector divisions to a pattern
recognised by the existing lowering logic.

For future reference, an example of code that would miscompile before
this patch is below:

  1  int8_t foo(unsigned N, int8_t *a, int8_t *b, int8_t *c) {
  2      int8_t result = 0;
  3      for (int i = 0; i < N; ++i) {
  4          result += (a[i] / b[i]) / c[i];
  5      }
  6      return result;
  7  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100370

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/sve-fixed-length-int-div.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100370.337072.patch
Type: text/x-patch
Size: 72758 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210413/d806823e/attachment.bin>


More information about the llvm-commits mailing list