Issue |
132714
|
Summary |
[x86-64 BMI2] Generating a bitstring with a `min(64, LEN)` 1 bits at the bottom should use `BZHI`
|
Labels |
new issue
|
Assignees |
|
Reporter |
Validark
|
This code: [Zig Godbolt](https://zig.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:18,fontUsePx:'0',j:3,lang:zig,selection:(endColumn:27,endLineNumber:2,positionColumn:27,positionLineNumber:2,selectionStartColumn:27,selectionStartLineNumber:2,startColumn:27,startLineNumber:2),source:'export+fn+foo(len:+u64)+u64+%7B%0A++++return+~if+(len+%3E%3D+64)+@as(u64,+0)+else+~@as(u64,+0)+%3C%3C+@intCast(len)%3B%0A%7D%0A%0Aexport+fn+bar(len:+u64)+u64+%7B%0A++++const+m+%3D+~@as(u64,+0)%3B%0A++++const+x+%3D+bzhi_builtin(m,+len)%3B%0A++++return+if+(len+%3E%3D+64)+m+else+x%3B%0A%7D%0A%0Afn+bzhi_builtin(src:+u64,+mask:+u64)+u64+%7B%0A++++return+struct+%7B%0A++++++++extern+fn+@%22llvm.x86.bmi.bzhi.64%22(u64,+u64)+u64%3B%0A++++%7D.@%22llvm.x86.bmi.bzhi.64%22(src,+mask)%3B%0A%7D%0A'),l:'5',n:'0',o:'Zig+source+%233',t:'0')),header:(),k:62.7177700348432,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:ztrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:zig,libs:!(),options:'-O+ReleaseFast+-target+x86_64-linux+-mcpu%3Dznver5',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:3),l:'5',n:'0',o:'+zig+trunk+(Editor+%233)',t:'0')),header:(),k:37.2822299651568,l:'4',m:100,n:'0',o:'',s:0,t:'0')),l:'2',m:100,n:'0',o:'',t:'0')),version:4)
```zig
export fn foo(len: u64) u64 {
return ~if (len >= 64)
@as(u64, 0)
else
~@as(u64, 0) << @intCast(len);
}
```
Gives me this emit:
```asm
mov rcx, -1
cmp rdi, 64
shlx rax, rcx, rdi
not rax
cmovae rax, rcx
```
Should be:
```asm
mov rcx, -1
bzhi rax, rcx, rdi
cmp rdi, 64
cmovae rax, rcx
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs