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

Anton Afanasyev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 10 11:27:13 PDT 2021


anton-afanasyev added a comment.

> Define good. I think supporting variable shifts will take exactly two lines:
> compute knownbits of the shift amount, and get the maximal shift amount via `KnownBits::getMaxValue()`.

Hmm, how could we compute knownbits of the shift amount at compile time? Do you mean analyzing DAG for the shift amount Value, taking knowbits recursively?
Also I don't believe this computing makes sense: for the most cases, when shift amount is variable, its first byte is unknown. For instance, how could knownbits help to optimize @spatel's example?

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


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