[PATCH] D94874: [InstCombine] Transform abs pattern using multiplication to abs intrinsic (PR45691)

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 17 06:48:16 PST 2021


xbolva00 created this revision.
Herald added a subscriber: hiraditya.
xbolva00 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

  unsigned r(int v)
  {
      return (1 | -(v < 0)) * v;
  }
  
  `r` is equivalent to `abs(v)`.

define <4 x i8> @src(<4 x i8> %0) {
%1:

  %2 = ashr <4 x i8> %0, { 31, undef, 31, 31 }
  %3 = or <4 x i8> %2, { 1, 1, 1, undef }
  %4 = mul nsw <4 x i8> %3, %0
  ret <4 x i8> %4

}

>
=

define <4 x i8> @tgt(<4 x i8> %0) {
%1:

  %2 = icmp slt <4 x i8> %0, { 0, 0, 0, 0 }
  %3 = sub nsw <4 x i8> { 0, 0, 0, 0 }, %0
  %4 = select <4 x i1> %2, <4 x i8> %3, <4 x i8> %0
  ret <4 x i8> %4

}
Transformation seems to be correct!

  foreach ($list as $item) {
    work_miracles($item);
  }

  foreach ($list as $item) {
    work_miracles($item);
  }


https://reviews.llvm.org/D94874

Files:
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/test/Transforms/InstCombine/ashr-or-mul-abs.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94874.317216.patch
Type: text/x-patch
Size: 4494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210117/5b9f18e8/attachment.bin>


More information about the llvm-commits mailing list