[all-commits] [llvm/llvm-project] e8af13: [InstCombine] Generalize trunc-shift-icmp fold fro...
Pedro Lobo via All-commits
all-commits at lists.llvm.org
Sat Nov 22 07:44:28 PST 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: e8af134bb7f891caa49178c8a04a8ca944c611df
https://github.com/llvm/llvm-project/commit/e8af134bb7f891caa49178c8a04a8ca944c611df
Author: Pedro Lobo <pedro.lobo at tecnico.ulisboa.pt>
Date: 2025-11-22 (Sat, 22 Nov 2025)
Changed paths:
M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
M llvm/test/Transforms/InstCombine/icmp-trunc.ll
Log Message:
-----------
[InstCombine] Generalize trunc-shift-icmp fold from (1 << Y) to (Pow2 << Y) (#169163)
Extends the `icmp(trunc(shl))` fold to handle any power of 2 constant as
the shift base, not just 1. This generalizes the following patterns by
adjusting the comparison offsets by `log2(Pow2)`.
```llvm
(trunc (1 << Y) to iN) == 0 --> Y u>= N
(trunc (1 << Y) to iN) != 0 --> Y u< N
(trunc (1 << Y) to iN) == 2**C --> Y == C
(trunc (1 << Y) to iN) != 2**C --> Y != C
; to
(trunc (Pow2 << Y) to iN) == 0 --> Y u>= N - log2(Pow2)
(trunc (Pow2 << Y) to iN) != 0 --> Y u< N - log2(Pow2)
(trunc (Pow2 << Y) to iN) == 2**C --> Y == C - log2(Pow2)
(trunc (Pow2 << Y) to iN) != 2**C --> Y != C - log2(Pow2)
```
Proof: https://alive2.llvm.org/ce/z/2zwTkp
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