Open Validark opened 9 months ago
@llvm/issue-subscribers-backend-x86
Author: Niles Salter (Validark)
define dso_local <64 x i8> @prev1(<64 x i8> %0, <64 x i8> %1) local_unnamed_addr {
%3 = shufflevector <64 x i8> %1, <64 x i8> %0, <64 x i32> <i32 63, i32 64, i32 65, i32 66, i32 67, i32 68, i32 69, i32 70, i32 71, i32 72, i32 73, i32 74, i32 75, i32 76, i32 77, i32 78, i32 79, i32 80, i32 81, i32 82, i32 83, i32 84, i32 85, i32 86, i32 87, i32 88, i32 89, i32 90, i32 91, i32 92, i32 93, i32 94, i32 95, i32 96, i32 97, i32 98, i32 99, i32 100, i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 107, i32 108, i32 109, i32 110, i32 111, i32 112, i32 113, i32 114, i32 115, i32 116, i32 117, i32 118, i32 119, i32 120, i32 121, i32 122, i32 123, i32 124, i32 125, i32 126>
ret <64 x i8> %3
}
define dso_local <64 x i8> @prev2(<64 x i8> %0, <64 x i8> %1) local_unnamed_addr {
%3 = shufflevector <64 x i8> %1, <64 x i8> %0, <64 x i32> <i32 62, i32 63, i32 64, i32 65, i32 66, i32 67, i32 68, i32 69, i32 70, i32 71, i32 72, i32 73, i32 74, i32 75, i32 76, i32 77, i32 78, i32 79, i32 80, i32 81, i32 82, i32 83, i32 84, i32 85, i32 86, i32 87, i32 88, i32 89, i32 90, i32 91, i32 92, i32 93, i32 94, i32 95, i32 96, i32 97, i32 98, i32 99, i32 100, i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 107, i32 108, i32 109, i32 110, i32 111, i32 112, i32 113, i32 114, i32 115, i32 116, i32 117, i32 118, i32 119, i32 120, i32 121, i32 122, i32 123, i32 124, i32 125>
ret <64 x i8> %3
}
define dso_local <64 x i8> @prev3(<64 x i8> %0, <64 x i8> %1) local_unnamed_addr {
%3 = shufflevector <64 x i8> %1, <64 x i8> %0, <64 x i32> <i32 61, i32 62, i32 63, i32 64, i32 65, i32 66, i32 67, i32 68, i32 69, i32 70, i32 71, i32 72, i32 73, i32 74, i32 75, i32 76, i32 77, i32 78, i32 79, i32 80, i32 81, i32 82, i32 83, i32 84, i32 85, i32 86, i32 87, i32 88, i32 89, i32 90, i32 91, i32 92, i32 93, i32 94, i32 95, i32 96, i32 97, i32 98, i32 99, i32 100, i32 101, i32 102, i32 103, i32 104, i32 105, i32 106, i32 107, i32 108, i32 109, i32 110, i32 111, i32 112, i32 113, i32 114, i32 115, i32 116, i32 117, i32 118, i32 119, i32 120, i32 121, i32 122, i32 123, i32 124>
ret <64 x i8> %3
}
@Validark Interestingly the zig IR output doesn't use optsize (or minsize) function attributes - it doesn't help here but its something I might look at adding support for to decide when to fold multiple shuffles into a variable shuffle mask
It's even worse for 32-byte vectors. VALIGNQ (YMM, YMM, YMM, I8) has a latency of 3 and VPALIGNR (YMM, YMM, YMM, I8) has a latency of 1, whereas VPERMT2W on 32-byte vectors is also 4 cycles, but requires a load from memory and/or an additional table occupying a register.
Godbolt link
emit:
Is this a real optimization or a mistake? The compiler also does not seem to revert back to
valignq+vpalignr
, even for size-optimized builds. It could be emitted like so in ReleaseSmall:According to uops.info, VALIGNQ (ZMM, ZMM, ZMM, I8) has a latency of 4 and VPALIGNR (ZMM, ZMM, ZMM, I8) has a latency of 2. Compare that to VMOVDQA64 (ZMM, M512) with a latency of [≤9;≤11] and VPERMT2W (ZMM, ZMM, ZMM) with a latency of 5;6. Is the compiler banking on the idea that maybe the CPU will hoist the load?