[PATCH] D151988: LoopVectorize: extend SelectCmp pattern for non-invariants

Ramkumar Ramachandra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 06:10:55 PDT 2023


artagnon updated this revision to Diff 528823.
artagnon added a comment.

Address @shiva0217's comment, and fix miscompile for the following case:

  int a[n] = {0, 0, 4, 3};
  int k = a[0];
  for (int i = 0; i < n; i++)
    if (a[i] > 2)
      k = a[i];
  return k;

Here, instead of i being maximized, a[i] is maximized. To forbid this
case, let us check that the SCEV AddRec expression has a constant step,
and not vectorize this case at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151988

Files:
  llvm/include/llvm/Analysis/IVDescriptors.h
  llvm/include/llvm/Transforms/Utils/LoopUtils.h
  llvm/lib/Analysis/IVDescriptors.cpp
  llvm/lib/Transforms/Utils/LoopUtils.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/if-reduction.ll
  llvm/test/Transforms/LoopVectorize/select-cmp.ll
  llvm/test/Transforms/LoopVectorize/select-min-index.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151988.528823.patch
Type: text/x-patch
Size: 33601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230606/72028c98/attachment.bin>


More information about the llvm-commits mailing list