[all-commits] [llvm/llvm-project] ed3962: [InstCombine] Transform abs pattern using multipli...

Dávid Bolvanský via All-commits all-commits at lists.llvm.org
Sun Jan 17 08:06:37 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ed396212da41feed9bffb8cc1ca6518ab031a3c7
      https://github.com/llvm/llvm-project/commit/ed396212da41feed9bffb8cc1ca6518ab031a3c7
  Author: Dávid Bolvanský <david.bolvansky at gmail.com>
  Date:   2021-01-17 (Sun, 17 Jan 2021)

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

  Log Message:
  -----------
  [InstCombine] Transform abs pattern using multiplication to abs intrinsic (PR45691)

```
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!
```

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D94874




More information about the All-commits mailing list