diff options
| author | Pavel Skripkin <paskripkin@gmail.com> | 2025-08-14 10:23:03 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-14 10:23:03 +0300 |
| commit | 30144226a4ea916341c37759d93dc2b32502efa1 (patch) | |
| tree | fa48065ddfb44378a247ea4ac826218b20b4bc1c /lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp | |
| parent | f92afe7171fcda7b1b69fd428925dd7655021226 (diff) | |
| download | llvm-30144226a4ea916341c37759d93dc2b32502efa1.zip llvm-30144226a4ea916341c37759d93dc2b32502efa1.tar.gz llvm-30144226a4ea916341c37759d93dc2b32502efa1.tar.bz2 | |
[llvm] [InstCombine] fold "icmp eq (X + (V - 1)) & -V, X" to "icmp eq (and X, V - 1), 0" (#152851)
This fold optimizes
```llvm
define i1 @src(i32 %num, i32 %val) {
%mask = add i32 %val, -1
%neg = sub nsw i32 0, %val
%num.biased = add i32 %num, %mask
%_2.sroa.0.0 = and i32 %num.biased, %neg
%_0 = icmp eq i32 %_2.sroa.0.0, %num
ret i1 %_0
}
```
to
```llvm
define i1 @tgt(i32 %num, i32 %val) {
%mask = add i32 %val, -1
%tmp = and i32 %num, %mask
%ret = icmp eq i32 %tmp, 0
ret i1 %ret
}
```
For power-of-two `val`.
Observed in real life for following code
```rust
pub fn is_aligned(num: usize) -> bool {
num.next_multiple_of(1 << 12) == num
}
```
which verifies that num is aligned to 4096.
Alive2 proof https://alive2.llvm.org/ce/z/QisECm
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp')
0 files changed, 0 insertions, 0 deletions
