[all-commits] [llvm/llvm-project] e6b678: [InstCombine] fold abs(X)/X to cmp+select

RotateRight via All-commits all-commits at lists.llvm.org
Mon Aug 17 05:01:56 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: e6b6787d01e9ea6338b5b51c6e3ba1b903876b3a
      https://github.com/llvm/llvm-project/commit/e6b6787d01e9ea6338b5b51c6e3ba1b903876b3a
  Author: Sanjay Patel <spatel at rotateright.com>
  Date:   2020-08-17 (Mon, 17 Aug 2020)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
    M llvm/test/Transforms/InstCombine/sdiv-canonicalize.ll

  Log Message:
  -----------
  [InstCombine] fold abs(X)/X to cmp+select

The backend can convert the select-of-constants to
bit-hack shift+logic if desirable.

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

  define i8 @src(i8 %x) {
  %0:
    %a = abs i8 %x, 1
    %d = sdiv i8 %x, %a
    ret i8 %d
  }
  =>
  define i8 @tgt(i8 %x) {
  %0:
    %cond = icmp sgt i8 %x, 255
    %r = select i1 %cond, i8 1, i8 255
    ret i8 %r
  }
  Transformation seems to be correct!




More information about the All-commits mailing list