[PATCH] D107766: [InstCombine] Get rid of `hasOneUses()` when swapping `lshr` and `zext`

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 9 08:59:31 PDT 2021


spatel added a comment.

If we want to solve this as an instcombine (or maybe aggressive-instcombine) problem, we have to expand the pattern to make it clearly profitable. I'm not sure how to generalize it, but we can do the narrowing starting from the trunc and remove an instruction:
https://alive2.llvm.org/ce/z/lwtDwZ

  define i16 @src(i8 %x) {
    %z = zext i8 %x to i32
    %s = lshr i32 %z, 1
    %a = add nuw nsw i32 %s, %z
    %s2 = lshr i32 %a, 2
    %t = trunc i32 %s2 to i16
    ret i16 %t
  }
  
  define i16 @tgt(i8 %x) {
    %z = zext i8 %x to i16
    %s = lshr i16 %z, 1
    %a = add nuw nsw i16 %s, %z
    %s2 = lshr i16 %a, 2
    ret i16 %s2
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107766/new/

https://reviews.llvm.org/D107766



More information about the llvm-commits mailing list