Issue 120389
Summary [AVX-512] `movemask(u8) & 1` generates `and al, 1` + `movzx eax, al` instead of `and eax, 1`
Labels new issue
Assignees
Reporter Validark
    Zig version: ([Godbolt](https://zig.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:zig,selection:(endColumn:1,endLineNumber:8,positionColumn:1,positionLineNumber:8,selectionStartColumn:1,selectionStartLineNumber:8,startColumn:1,startLineNumber:8),source:'export+fn+doo(b:+u8)+u64+%7B%0A++++return+((b+%3E%3E+0)+%26+1)%3B%0A%7D%0A%0Aexport+fn+zoom(args:+@Vector(8,+i64))+u64+%7B%0A++++return+doo(@bitCast(args+%3C+@as(@TypeOf(args),+@splat(0))))%3B%0A%7D%0A'),l:'5',n:'0',o:'Zig+source+%231',t:'0')),k:50,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:1,lang:zig,libs:!(),options:'-O+ReleaseFast+-mcpu%3Dznver5+-target+x86_64-linux',overrides:!(),selection:(endColumn:24,endLineNumber:15,positionColumn:24,positionLineNumber:15,selectionStartColumn:24,selectionStartLineNumber:15,startColumn:24,startLineNumber:15),source:1),l:'5',n:'0',o:'+zig+trunk+(Editor+%231)',t:'0')),header:(),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4))

```zig
export fn doo(b: u8) u64 {
    return ((b >> 0) & 1);
}

export fn zoom(args: @Vector(8, i64)) u64 {
    return doo(@bitCast(args < @as(@TypeOf(args), @splat(0))));
}
```

LLVM version:

```llvm
define dso_local range(i64 0, 2) i64 @doo(i8 zeroext %0) local_unnamed_addr {
Entry:
  %1 = and i8 %0, 1
  %2 = zext nneg i8 %1 to i64
  ret i64 %2
}

define dso_local range(i64 0, 2) i64 @zoom(<8 x i64> %0) local_unnamed_addr {
Entry:
  %1 = icmp slt <8 x i64> %0, zeroinitializer
  %2 = bitcast <8 x i1> %1 to i8
 %3 = and i8 %2, 1
  %4 = zext nneg i8 %3 to i64
  ret i64 %4
}
```

Compiled for znver5:

```diff
doo:
        push    rbp
 mov     rbp, rsp
        mov     eax, edi
        and     eax, 1
 pop     rbp
        ret

zoom:
        push    rbp
        mov rbp, rsp
        vpmovq2m        k0, zmm0
        kmovd   eax, k0
- and     al, 1
-       movzx   eax, al
+       and     eax, 1
        pop rbp
        vzeroupper
        ret
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to