[all-commits] [llvm/llvm-project] 935838: [InstCombine] Extend canonicalizeClampLike to hand...

David Green via All-commits all-commits at lists.llvm.org
Thu Oct 28 07:47:10 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9358384fd646aa0999ced1d4fafd294c14680527
      https://github.com/llvm/llvm-project/commit/9358384fd646aa0999ced1d4fafd294c14680527
  Author: David Green <david.green at arm.com>
  Date:   2021-10-28 (Thu, 28 Oct 2021)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
    M llvm/test/Transforms/InstCombine/truncating-saturate.ll

  Log Message:
  -----------
  [InstCombine] Extend canonicalizeClampLike to handle truncated inputs

This extends the canonicalizeClampLike function to allow cases where the
input is truncated, but still matching on the types of the ICmps. For
example
  %t = trunc i32 %X to i8
  %a = add i32 %X, 128
  %cmp = icmp ult i32 %a, 256
  %c = icmp sgt i32 %X, -1
  %f = select i1 %c, i8 High, i8 Low
  %r = select i1 %cmp, i8 %t, i8 %f
becomes
  %c1 = icmp slt i32 %X, -128
  %c2 = icmp sge i32 %X, 128
  %s1 = select i1 %c1, i32 sext(Low), i32 %X
  %s2 = select i1 %c2, i32 sext(High), i32 %s1
  %t = trunc i32 %s2 to i8
https://alive2.llvm.org/ce/z/vPzfxH

We limit the transform to constant High and Low values, where we know
the sext are free.

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




More information about the All-commits mailing list