llvm-project/llvm/test/CodeGen/X86/avx512-load-trunc-store-i1.ll
Sanjay Patel f0dd12ec5c [x86] use zero-extending load of a byte outside of loops too (2nd try)
The first attempt missed changing test files for tools
(update_llc_test_checks.py).

Original commit message:

This implements the main suggested change from issue #56498.
Using the shorter (non-extending) instruction with only
-Oz ("minsize") rather than -Os ("optsize") is left as a
possible follow-up.

As noted in the bug report, the zero-extending load may have
shorter latency/better throughput across a wide range of x86
micro-arches, and it avoids a potential false dependency.
The cost is an extra instruction byte.

This could cause perf ups and downs from secondary effects,
but I don't think it is possible to account for those in
advance, and that will likely also depend on exact micro-arch.
This does bring LLVM x86 codegen more in line with existing
gcc codegen, so if problems are exposed they are more likely
to occur for both compilers.

Differential Revision: https://reviews.llvm.org/D129775
2022-07-19 21:27:08 -04:00

160 lines
5.5 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512f,+avx512bw,+avx512vl,+avx512dq -O2 | FileCheck %s --check-prefix=AVX512-ALL
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512f -O2| FileCheck %s --check-prefix=AVX512-ONLY
define void @load_v1i2_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i2_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i2_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i2>, ptr %a0
%d1 = trunc <1 x i2> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}
define void @load_v1i3_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i3_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i3_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i3>, ptr %a0
%d1 = trunc <1 x i3> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}
define void @load_v1i4_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i4_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i4_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i4>, ptr %a0
%d1 = trunc <1 x i4> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}
define void @load_v1i8_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i8_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i8_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i8>, ptr %a0
%d1 = trunc <1 x i8> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}
define void @load_v1i16_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i16_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i16_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i16>, ptr %a0
%d1 = trunc <1 x i16> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}
define void @load_v1i32_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i32_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i32_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i32>, ptr %a0
%d1 = trunc <1 x i32> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}
define void @load_v1i64_trunc_v1i1_store(ptr %a0,ptr %a1) {
; AVX512-ALL-LABEL: load_v1i64_trunc_v1i1_store:
; AVX512-ALL: # %bb.0:
; AVX512-ALL-NEXT: kmovb (%rdi), %k0
; AVX512-ALL-NEXT: kshiftlb $7, %k0, %k0
; AVX512-ALL-NEXT: kshiftrb $7, %k0, %k0
; AVX512-ALL-NEXT: kmovb %k0, (%rsi)
; AVX512-ALL-NEXT: retq
;
; AVX512-ONLY-LABEL: load_v1i64_trunc_v1i1_store:
; AVX512-ONLY: # %bb.0:
; AVX512-ONLY-NEXT: movzbl (%rdi), %eax
; AVX512-ONLY-NEXT: andl $1, %eax
; AVX512-ONLY-NEXT: kmovw %eax, %k0
; AVX512-ONLY-NEXT: kmovw %k0, %eax
; AVX512-ONLY-NEXT: movb %al, (%rsi)
; AVX512-ONLY-NEXT: retq
%d0 = load <1 x i64>, ptr %a0
%d1 = trunc <1 x i64> %d0 to <1 x i1>
store <1 x i1> %d1, ptr %a1
ret void
}