diff options
author | David Majnemer <david.majnemer@gmail.com> | 2024-10-27 23:51:20 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2024-10-28 05:13:04 +0000 |
commit | 5d4a0d54b5269bad1410e6db957836fe98634069 (patch) | |
tree | 6f7be32b8e81a793b8856058d17727557a070041 /llvm/lib/CodeGen/MachineOperand.cpp | |
parent | d3f70db51cbc0876937d404e96fbda04df793bd4 (diff) | |
download | llvm-5d4a0d54b5269bad1410e6db957836fe98634069.zip llvm-5d4a0d54b5269bad1410e6db957836fe98634069.tar.gz llvm-5d4a0d54b5269bad1410e6db957836fe98634069.tar.bz2 |
[InstCombine] Teach takeLog2 about right shifts, truncation and bitwise-and
We left some easy opportunities for further simplifications.
log2(trunc(x)) is simply trunc(log2(x)). This is safe if we know that
trunc is NUW because it means that the truncation didn't drop any bits.
It is also safe if the caller is OK with zero as a possible answer.
log2(x >>u y) is simply `log2(x) - y`.
log2(x & y) is a funny one. It comes up when doing something like:
```
unsigned int f(unsigned int x, unsigned int y) {
unsigned char a = 1u << x;
return y / a;
}
```
LLVM would canonicalize this to:
```
%shl = shl nuw i32 1, %x
%conv1 = and i32 %shl, 255
%div = udiv i32 %y, %conv1
```
In cases like these, we can ignore the mask entirely.
This is equivalent to `y >> x`.
Diffstat (limited to 'llvm/lib/CodeGen/MachineOperand.cpp')
0 files changed, 0 insertions, 0 deletions