[all-commits] [llvm/llvm-project] 83c2d1: [NFC][SCEV] Add tests for @llvm.abs intrinsic

Roman Lebedev via All-commits all-commits at lists.llvm.org
Mon Sep 21 10:26:45 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 83c2d10d3cae57f71e23193d62989725b9b9f2f2
      https://github.com/llvm/llvm-project/commit/83c2d10d3cae57f71e23193d62989725b9b9f2f2
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-09-21 (Mon, 21 Sep 2020)

  Changed paths:
    A llvm/test/Analysis/ScalarEvolution/abs-intrinsic.ll

  Log Message:
  -----------
  [NFC][SCEV] Add tests for @llvm.abs intrinsic


  Commit: 1bb7ab8c4a324aa380bddfc75069e24c19e2bdd0
      https://github.com/llvm/llvm-project/commit/1bb7ab8c4a324aa380bddfc75069e24c19e2bdd0
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-09-21 (Mon, 21 Sep 2020)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/abs-intrinsic.ll

  Log Message:
  -----------
  [SCEV] Recognize @llvm.abs as smax(x, -x)

As per alive2 (ignoring undef):

----------------------------------------
define i32 @src(i32 %x, i1 %y) {
%0:
  %r = abs i32 %x, 0
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i1 %y) {
%0:
  %neg_x = mul i32 %x, 4294967295
  %r = smax i32 %x, %neg_x
  ret i32 %r
}
Transformation seems to be correct!

----------------------------------------
define i32 @src(i32 %x, i1 %y) {
%0:
  %r = abs i32 %x, 1
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i1 %y) {
%0:
  %neg_x = mul nsw i32 %x, 4294967295
  %r = smax i32 %x, %neg_x
  ret i32 %r
}
Transformation seems to be correct!


  Commit: 0592de550f5c9ca9de44ed2c5c549f6a3b1c32b7
      https://github.com/llvm/llvm-project/commit/0592de550f5c9ca9de44ed2c5c549f6a3b1c32b7
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-09-21 (Mon, 21 Sep 2020)

  Changed paths:
    A llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll

  Log Message:
  -----------
  [NFC][SCEV] Add tests for @llvm.*.sat intrinsics


  Commit: fedc9549d50d80f74169ecce4d0d0648a62249f0
      https://github.com/llvm/llvm-project/commit/fedc9549d50d80f74169ecce4d0d0648a62249f0
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-09-21 (Mon, 21 Sep 2020)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll

  Log Message:
  -----------
  [SCEV] Recognize @llvm.usub.sat as `%x - (umin %x, %y)`

----------------------------------------
define i32 @src(i32 %x, i32 %y) {
%0:
  %r = usub_sat i32 %x, %y
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i32 %y) {
%0:
  %t0 = umin i32 %x, %y
  %r = sub nuw i32 %x, %t0
  ret i32 %r
}
Transformation seems to be correct!


  Commit: 64e2cb7e9605995d2efb625203cbd96db1404812
      https://github.com/llvm/llvm-project/commit/64e2cb7e9605995d2efb625203cbd96db1404812
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-09-21 (Mon, 21 Sep 2020)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/Analysis/ScalarEvolution/saturating-intrinsics.ll

  Log Message:
  -----------
  [SCEV] Recognize @llvm.uadd.sat as `%y + umin(%x, (-1 - %y))`

----------------------------------------
define i32 @src(i32 %x, i32 %y) {
%0:
  %r = uadd_sat i32 %x, %y
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i32 %y) {
%0:
  %t0 = sub nsw nuw i32 4294967295, %y
  %t1 = umin i32 %x, %t0
  %r = add nuw i32 %t1, %y
  ret i32 %r
}
Transformation seems to be correct!

The alternative, naive, lowering could be the following,
although i don't think it's better,
thought it will likely be needed for sadd/ssub/*shl:

----------------------------------------
define i32 @src(i32 %x, i32 %y) {
%0:
  %r = uadd_sat i32 %x, %y
  ret i32 %r
}
=>
define i32 @tgt(i32 %x, i32 %y) {
%0:
  %t0 = zext i32 %x to i33
  %t1 = zext i32 %y to i33
  %t2 = add nuw i33 %t0, %t1
  %t3 = zext i32 4294967295 to i33
  %t4 = umin i33 %t2, %t3
  %r = trunc i33 %t4 to i32
  ret i32 %r
}
Transformation seems to be correct!


Compare: https://github.com/llvm/llvm-project/compare/005f826a0546...64e2cb7e9605


More information about the All-commits mailing list