-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AVX2] vectorized a == (a & b)
should not be switched to 0 != (a & b)
when it doesn't help
#110875
Comments
@llvm/issue-subscribers-backend-x86 Author: Niles Salter (Validark)
In trying to work around https://github.com//issues/110868, I wrote this code:
LLVM Godbolt Zig version: const std = @<!-- -->import("std");
fn unmovemask64(x: u64) @<!-- -->Vector(64, bool) {
const bit_positions = comptime std.simd.repeat(64, @<!-- -->as(@<!-- -->Vector(8, u8), @<!-- -->splat(1)) << std.simd.iota(u3, 8));
return bit_positions == (bit_positions & @<!-- -->shuffle(u8, @<!-- -->as(@<!-- -->Vector(64, u8), @<!-- -->bitCast(@<!-- -->as(@<!-- -->Vector(8, u64), @<!-- -->splat(x)))), undefined, (std.simd.iota(u8, 64) >> @<!-- -->splat(4) << @<!-- -->splat(4)) + (std.simd.iota(u8, 64) >> @<!-- -->splat(3))));
}
export fn bar(kinds_1: @<!-- -->Vector(32, u8), kinds_2: @<!-- -->Vector(32, u8), comment_starts: u64) @<!-- -->Vector(64, u8) {
const kinds = std.simd.join(kinds_1, kinds_2); // helps the C ABI
return @<!-- -->select(u8, unmovemask64(comment_starts), @<!-- -->as(@<!-- -->Vector(64, u8), @<!-- -->splat(20)), kinds);
} LLVM version: define dso_local <64 x i8> @<!-- -->bar(<32 x i8> %0, <32 x i8> %1, i64 %2) local_unnamed_addr {
Entry:
%3 = shufflevector <32 x i8> %0, <32 x i8> %1, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>
%4 = insertelement <1 x i64> poison, i64 %2, i64 0
%5 = shufflevector <1 x i64> %4, <1 x i64> poison, <8 x i32> <i32 0, i32 poison, i32 0, i32 poison, i32 0, i32 poison, i32 0, i32 poison>
%6 = bitcast <8 x i64> %5 to <64 x i8>
%7 = shufflevector <64 x i8> %6, <64 x i8> poison, <64 x i32> <i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 18, i32 18, i32 18, i32 18, i32 18, i32 18, i32 18, i32 18, i32 19, i32 19, i32 19, i32 19, i32 19, i32 19, i32 19, i32 19, i32 36, i32 36, i32 36, i32 36, i32 36, i32 36, i32 36, i32 36, i32 37, i32 37, i32 37, i32 37, i32 37, i32 37, i32 37, i32 37, i32 54, i32 54, i32 54, i32 54, i32 54, i32 54, i32 54, i32 54, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55>
%8 = and <64 x i8> %7, <i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128, i8 1, i8 2, i8 4, i8 8, i8 16, i8 32, i8 64, i8 -128>
%.not = icmp eq <64 x i8> %8, zeroinitializer
%9 = select <64 x i1> %.not, <64 x i8> %3, <64 x i8> <i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20, i8 20>
ret <64 x i8> %9
} The Zen 3 assembly is: .LCPI0_0:
.byte 4
.byte 4
.byte 4
.byte 4
.byte 4
.byte 4
.byte 4
.byte 4
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 5
.byte 6
.byte 6
.byte 6
.byte 6
.byte 6
.byte 6
.byte 6
.byte 6
.byte 7
.byte 7
.byte 7
.byte 7
.byte 7
.byte 7
.byte 7
.byte 7
.LCPI0_1:
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 1
.byte 1
.byte 1
.byte 1
.byte 1
.byte 1
.byte 1
.byte 1
.byte 2
.byte 2
.byte 2
.byte 2
.byte 2
.byte 2
.byte 2
.byte 2
.byte 3
.byte 3
.byte 3
.byte 3
.byte 3
.byte 3
.byte 3
.byte 3
.zero 32,20
.LCPI0_2:
.byte 1
.byte 2
.byte 4
.byte 8
.byte 16
.byte 32
.byte 64
.byte 128
.LCPI0_4:
.byte 20
bar:
vmovq xmm2, rdi
vpbroadcastq ymm4, qword ptr [rip + .LCPI0_2]
vpbroadcastb ymm5, byte ptr [rip + .LCPI0_4]
vpbroadcastq ymm2, xmm2
vpshufb ymm3, ymm2, ymmword ptr [rip + .LCPI0_0]
vpshufb ymm2, ymm2, ymmword ptr [rip + .LCPI0_1]
vpand ymm2, ymm2, ymm4
vpand ymm3, ymm3, ymm4
- vpxor xmm4, xmm4, xmm4
vpcmpeqb ymm3, ymm3, ymm4
vpcmpeqb ymm2, ymm2, ymm4
vpblendvb ymm0, ymm0, ymm5, ymm2 ; deletion of the `vpxor` instruction requires that
vpblendvb ymm1, ymm1, ymm5, ymm3 ; the 2nd and 3rd arguments should be switched
ret |
In trying to work around #110868, I wrote this code:
LLVM Godbolt
Zig Godbolt
Zig version:
LLVM version:
The Zen 3 assembly is:
.LCPI0_0: .byte 4 .byte 4 .byte 4 .byte 4 .byte 4 .byte 4 .byte 4 .byte 4 .byte 5 .byte 5 .byte 5 .byte 5 .byte 5 .byte 5 .byte 5 .byte 5 .byte 6 .byte 6 .byte 6 .byte 6 .byte 6 .byte 6 .byte 6 .byte 6 .byte 7 .byte 7 .byte 7 .byte 7 .byte 7 .byte 7 .byte 7 .byte 7 .LCPI0_1: .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 1 .byte 1 .byte 1 .byte 1 .byte 1 .byte 1 .byte 1 .byte 1 .byte 2 .byte 2 .byte 2 .byte 2 .byte 2 .byte 2 .byte 2 .byte 2 .byte 3 .byte 3 .byte 3 .byte 3 .byte 3 .byte 3 .byte 3 .byte 3 .zero 32,20 .LCPI0_2: .byte 1 .byte 2 .byte 4 .byte 8 .byte 16 .byte 32 .byte 64 .byte 128 .LCPI0_4: .byte 20 bar: vmovq xmm2, rdi vpbroadcastq ymm4, qword ptr [rip + .LCPI0_2] vpbroadcastb ymm5, byte ptr [rip + .LCPI0_4] vpbroadcastq ymm2, xmm2 vpshufb ymm3, ymm2, ymmword ptr [rip + .LCPI0_0] vpshufb ymm2, ymm2, ymmword ptr [rip + .LCPI0_1] vpand ymm2, ymm2, ymm4 vpand ymm3, ymm3, ymm4 - vpxor xmm4, xmm4, xmm4 vpcmpeqb ymm3, ymm3, ymm4 vpcmpeqb ymm2, ymm2, ymm4 vpblendvb ymm0, ymm0, ymm5, ymm2 ; deletion of the `vpxor` instruction requires that vpblendvb ymm1, ymm1, ymm5, ymm3 ; the 2nd and 3rd arguments should be switched ret
The text was updated successfully, but these errors were encountered: