[all-commits] [llvm/llvm-project] 32dd91: [InstCombine][tests] add tests for signed icmp wit...

RotateRight via All-commits all-commits at lists.llvm.org
Mon Jul 5 07:19:31 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 32dd914f7182875730eb3453f39dcc584b7219b2
      https://github.com/llvm/llvm-project/commit/32dd914f7182875730eb3453f39dcc584b7219b2
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2021-07-05 (Mon, 05 Jul 2021)

  Changed paths:
    M llvm/test/Transforms/InstCombine/icmp-add.ll

  Log Message:
  -----------
  [InstCombine][tests] add tests for signed icmp with constant and offset; NFC


  Commit: 40b752d28d95158e52dba7cfeea92e41b7ccff9a
      https://github.com/llvm/llvm-project/commit/40b752d28d95158e52dba7cfeea92e41b7ccff9a
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2021-07-05 (Mon, 05 Jul 2021)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    M llvm/test/Transforms/InstCombine/icmp-add.ll

  Log Message:
  -----------
  [InstCombine] fold icmp slt/sgt of offset value with constant

This follows up patches for the unsigned siblings:
0c400e895306
c7b658aeb526

We are translating an offset signed compare to its
unsigned equivalent when one end of the range is
at the limit (zero or unsigned max).

(X + C2) >s C --> X <u (SMAX - C) (if C == C2 - 1)
(X + C2) <s C --> X >u (C ^ SMAX) (if C == C2)

This probably does not show up much in IR derived
from C/C++ source because that would likely have
'nsw', and we have folds for that already.

As with the previous unsigned transforms, the folds
could be generalized to handle non-constant patterns:

https://alive2.llvm.org/ce/z/Y8Xrrm

  ; sgt
  define i1 @src(i8 %a, i8 %c) {
    %c2 = add i8 %c, 1
    %t = add i8 %a, %c2
    %ov = icmp sgt i8 %t, %c
    ret i1 %ov
  }

  define i1 @tgt(i8 %a, i8 %c) {
    %c_off = sub i8 127, %c ; SMAX
    %ov = icmp ult i8 %a, %c_off
    ret i1 %ov
  }

https://alive2.llvm.org/ce/z/c8uhnk

  ; slt
  define i1 @src(i8 %a, i8 %c) {
    %t = add i8 %a, %c
    %ov = icmp slt i8 %t, %c
    ret i1 %ov
  }

  define i1 @tgt(i8 %a, i8 %c) {
    %c_offnot = xor i8 %c, 127 ; SMAX
    %ov = icmp ugt i8 %a, %c_offnot
    ret i1 %ov
  }


Compare: https://github.com/llvm/llvm-project/compare/a2c5c5605576...40b752d28d95


More information about the All-commits mailing list