[all-commits] [llvm/llvm-project] 265b03: [InstCombine] Added optimisation for trunc (Pow2 >...

kper via All-commits all-commits at lists.llvm.org
Wed Sep 10 08:54:39 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 265b032bdae0550de69ff52b4ef9deaf78bae522
      https://github.com/llvm/llvm-project/commit/265b032bdae0550de69ff52b4ef9deaf78bae522
  Author: kper <kevin.per at protonmail.com>
  Date:   2025-09-10 (Wed, 10 Sep 2025)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
    M llvm/test/Transforms/InstCombine/trunc-lshr.ll

  Log Message:
  -----------
  [InstCombine] Added optimisation for trunc (Pow2 >> x) to i1 (#157030)

Closes #156898

I have added two cases. The first one matches when the constant is
exactly power of 2. The second case was to address the general case
mentioned in the linked issue. I, however, did not really solve the
general case.
We can only emit a `icmp ult` if all the bits are one and that's only
the case when the constant + 1 is a power of 2. Otherwise, we need to
create `icmp eq` for every bit that is one.

Here are a few examples which won't be working with the two cases:
-  constant is `9`: https://alive2.llvm.org/ce/z/S5FLJZ
- subrange in `56`: https://alive2.llvm.org/ce/z/yn_ZNG
- and finally an example as worst case (because it alternates the bits):
https://alive2.llvm.org/ce/z/nDitNA



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list