Issue 169830
Summary [x86-64 AVX] Look to replace `shift+AND => blend+shift`
Labels new issue
Assignees
Reporter Validark
    [Zig Godbolt](https://zig.godbo.lt/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:11,fontUsePx:'0',j:1,lang:zig,selection:(endColumn:36,endLineNumber:9,positionColumn:36,positionLineNumber:9,selectionStartColumn:36,selectionStartLineNumber:9,startColumn:36,startLineNumber:9),source:'const+V+%3D+@Vector(4,+u64)%3B%0Aconst+Vd+%3D+@Vector(4,+u32)%3B%0A%0Aexport+fn+foo(a:+V)+V+%7B%0A++++return+@as(V,+@as(Vd,+@truncate(a)))+%3E%3E+@splat(11)%3B%0A%7D%0A%0Aexport+fn+bar(a:+V)+V+%7B%0A++++return+@as(V,+@bitCast(@select(%0A++++++++u32,%0A++++++++@as(@Vector(8,+bool),+@bitCast(@as(u8,+0xAA))),%0A++++++++@as(@Vector(8,+u32),+@splat(0)),%0A++++++++@as(@Vector(8,+u32),+@bitCast(a)),%0A++++)))+%3E%3E+@splat(11)%3B%0A%7D%0A'),l:'5',n:'0',o:'Zig+source+%231',t:'0')),k:54.779756443263146,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:z0152,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%3Dhaswell+-fomit-frame-pointer',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+zig+0.15.2+(Editor+%231)',t:'0')),k:45.22024355673687,l:'4',m:100,n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
[LLVM Godbolt](https://llvm.godbo.lt/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:2,endLineNumber:6,positionColumn:2,positionLineNumber:6,selectionStartColumn:2,selectionStartLineNumber:6,startColumn:2,startLineNumber:6),source:'define+dso_local+range(i64+0,+2097152)+%3C4+x+i64%3E+@foo(%3C4+x+i64%3E+%250)+local_unnamed_addr+%7B%0AEntry:%0A++%251+%3D+lshr+%3C4+x+i64%3E+%250,+splat+(i64+11)%0A++%252+%3D+and+%3C4+x+i64%3E+%251,+splat+(i64+2097151)%0A++ret+%3C4+x+i64%3E+%252%0A%7D'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:50.76820307281229,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:llctrunk,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:1,lang:llvm,libs:!(),options:'-O3+-mcpu%3Dznver5',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+llc+(trunk)+(Editor+%231)',t:'0')),k:49.23179692718771,l:'4',m:100,n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

```zig
const V = @Vector(4, u64);
const Vd = @Vector(4, u32);

export fn foo(a: V) V {
    return @as(V, @as(Vd, @truncate(a))) >> @splat(11);
}
```

Currently:

```asm
.LCPI0_0:
        .quad 2097151
foo:
        vpsrlq  ymm0, ymm0, 11
        vpandq  ymm0, ymm0, qword ptr [rip + .LCPI0_0]{1to4}
        ret
```

Could be:

```asm
bar:
        vpxor   xmm1, xmm1, xmm1
        vpblendd ymm0, ymm0, ymm1, 170
        vpsrlq  ymm0, ymm0, 11
        ret
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to