Issue |
90000
|
Summary |
`@min(@ctz(x), y)` can become `@ctz(x | (1 << y))`
|
Labels |
new issue
|
Assignees |
|
Reporter |
Validark
|
[Godbolt link](https://zig.godbolt.org/z/fzMo9jYPK)
```zig
export fn bounded_tzcnt(x: u16) u8 {
return @min(@ctz(x), y);
}
export fn bounded_tzcnt_better(x: u16) u8 {
return @ctz(x | (1 << y));
}
export fn bounded_lzcnt(x: u16) u8 {
return @min(@clz(x), y);
}
export fn bounded_lzcnt_better(x: u16) u8 {
return @clz(x | (1 << 16 >> y));
}
```
```asm
bounded_tzcnt:
or edi, 65536
mov eax, 6
tzcnt ecx, edi
cmp cl, 6
cmovb eax, ecx
ret
bounded_tzcnt_better:
or edi, 64
tzcnt eax, edi
ret
bounded_lzcnt:
lzcnt cx, di
mov eax, 6
cmp cl, 6
cmovb eax, ecx
ret
bounded_lzcnt_better:
or edi, 1024
lzcnt ax, di
ret
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs