Skip to content

[X86] cttz.elts +avx512f always returns 16 #216649

Description

@yrouban

The problem is that with target +avx512f the following intrinsic call returns 16 (the full target vector length) instead of 4 (the number of elements in the input vector):
call i32 @llvm.experimental.cttz.elts.i32.v4i1(<4 x i1> zeroinitializer, i1 false)

Here is the full repro main.ll:

target triple = "x86_64-unknown-linux"

define i32 @main() #0 {
entry:
  %first.inactive.lane = call i32 @llvm.experimental.cttz.elts.i32.v4i1(<4 x i1> zeroinitializer, i1 false)
  ret i32 %first.inactive.lane
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.experimental.cttz.elts.i32.v4i1(<4 x i1>, i1 immarg) #1

attributes #0 = \{ "target-features"="+avx512f" }
attributes #1 = \{ nocallback nofree nosync nounwind speculatable willreturn memory(none) }

To reproduce make an x86_64 executable and run:

$ llc main.ll --filetype=obj -o main.o && g++ main.o -o main && ./main; echo "Returned $?. Expected 4"
Returned 16. Expected 4

Compare the outputs of trunk and llc 22.1.0 (https://godbolt.org/z/Pxb54K4M9 ):

.LCPI0_0:
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
  .byte 255 # 0xff
  .byte 0 # 0x0
main: # @main
  vphminposuw xmm0, xmmword ptr [rip + .LCPI0_0]
  vmovd eax, xmm0
  add al, 17
  movzx eax, al
  ret

and

main: # @main
  mov eax, 4
  ret

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions