================
@@ -0,0 +1,357 @@
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux -target-feature +avx10.2 -fclangir -emit-cir -o 
%t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux -target-feature +avx10.2 -fclangir -emit-llvm -o 
%t.ll
+// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux -target-feature +avx10.2 -emit-llvm -o %t.ll
+// RUN: FileCheck --check-prefixes=OGCG --input-file=%t.ll %s
+
+#include <immintrin.h>
+
+
+__m128i test_selectb_128(__mmask16 k, __m128i a, __m128i b) {
+  // CIR-LABEL: @test_selectb_128
+  // CIR: %[[MASK_BC:.+]] = cir.cast bitcast %{{.+}} : !u16i -> !cir.vector<16 
x !cir.int<s, 1>>
+  // CIR: cir.vec.ternary(%[[MASK_BC]], %{{.+}}, %{{.+}}) : !cir.vector<16 x 
!cir.int<s, 1>>, !cir.vector<16 x !s8i>
+
+  // LLVM-LABEL: @test_selectb_128
+  // LLVM: select <16 x i1> %{{.+}}, <16 x i8> %{{.+}}, <16 x i8> %{{.+}}
+
+  // OGCG-LABEL: @test_selectb_128
+  // OGCG: select <16 x i1> %{{.+}}, <16 x i8> %{{.+}}, <16 x i8> %{{.+}}
+  return (__m128i)__builtin_ia32_selectb_128(k, (__v16qi)a, (__v16qi)b);
+}
+
+__m256i test_selectb_256(__mmask32 k, __m256i a, __m256i b) {
+  // CIR-LABEL: @test_selectb_256
+  // CIR: %[[MASK_BC:.+]] = cir.cast bitcast %{{.+}} : !u32i -> !cir.vector<32 
x !cir.int<s, 1>>
+  // CIR: cir.vec.ternary(%[[MASK_BC]], %{{.+}}, %{{.+}}) : !cir.vector<32 x 
!cir.int<s, 1>>, !cir.vector<32 x !s8i>
+
+  // LLVM-LABEL: @test_selectb_256
+  // LLVM: select <32 x i1> %{{.+}}, <32 x i8> %{{.+}}, <32 x i8> %{{.+}}
+
+  // OGCG-LABEL: @test_selectb_256
+  // OGCG: select <32 x i1> %{{.+}}, <32 x i8> %{{.+}}, <32 x i8> %{{.+}}
+  return (__m256i)__builtin_ia32_selectb_256(k, (__v32qi)a, (__v32qi)b);
+}
+
+__m512i test_selectb_512(__mmask64 k, __m512i a, __m512i b) {
+  // CIR-LABEL: @test_selectb_512
+  // CIR: %[[MASK_BC:.+]] = cir.cast bitcast %{{.+}} : !u64i -> !cir.vector<64 
x !cir.int<s, 1>>
+  // CIR: cir.vec.ternary(%[[MASK_BC]], %{{.+}}, %{{.+}}) : !cir.vector<64 x 
!cir.int<s, 1>>, !cir.vector<64 x !s8i>
+
+  // LLVM-LABEL: @test_selectb_512
+  // LLVM: select <64 x i1> %{{.+}}, <64 x i8> %{{.+}}, <64 x i8> %{{.+}}
+
+  // OGCG-LABEL: @test_selectb_512
+  // OGCG: select <64 x i1> %{{.+}}, <64 x i8> %{{.+}}, <64 x i8> %{{.+}}
+  return (__m512i)__builtin_ia32_selectb_512(k, (__v64qi)a, (__v64qi)b);
+}
+
+__m128i test_selectw_128(__mmask8 k, __m128i a, __m128i b) {
+  // CIR-LABEL: @test_selectw_128
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<8 x 
!cir.int<s, 1>>, !cir.vector<8 x !s16i>
+
+  // LLVM-LABEL: @test_selectw_128
+  // LLVM: select <8 x i1> %{{.+}}, <8 x i16> %{{.+}}, <8 x i16> %{{.+}}
+
+  // OGCG-LABEL: @test_selectw_128
+  // OGCG: select <8 x i1> %{{.+}}, <8 x i16> %{{.+}}, <8 x i16> %{{.+}}
+  return (__m128i)__builtin_ia32_selectw_128(k, (__v8hi)a, (__v8hi)b);
+}
+
+__m256i test_selectw_256(__mmask16 k, __m256i a, __m256i b) {
+  // CIR-LABEL: @test_selectw_256
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<16 x 
!cir.int<s, 1>>, !cir.vector<16 x !s16i>
+
+  // LLVM-LABEL: @test_selectw_256
+  // LLVM: select <16 x i1> %{{.+}}, <16 x i16> %{{.+}}, <16 x i16> %{{.+}}
+
+  // OGCG-LABEL: @test_selectw_256
+  // OGCG: select <16 x i1> %{{.+}}, <16 x i16> %{{.+}}, <16 x i16> %{{.+}}
+  return (__m256i)__builtin_ia32_selectw_256(k, (__v16hi)a, (__v16hi)b);
+}
+
+__m512i test_selectw_512(__mmask32 k, __m512i a, __m512i b) {
+  // CIR-LABEL: @test_selectw_512
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<32 x 
!cir.int<s, 1>>, !cir.vector<32 x !s16i>
+
+  // LLVM-LABEL: @test_selectw_512
+  // LLVM: select <32 x i1> %{{.+}}, <32 x i16> %{{.+}}, <32 x i16> %{{.+}}
+
+  // OGCG-LABEL: @test_selectw_512
+  // OGCG: select <32 x i1> %{{.+}}, <32 x i16> %{{.+}}, <32 x i16> %{{.+}}
+  return (__m512i)__builtin_ia32_selectw_512(k, (__v32hi)a, (__v32hi)b);
+}
+
+__m128i test_selectd_128(__mmask8 k, __m128i a, __m128i b) {
+  // CIR-LABEL: @test_selectd_128
+  // CIR: %[[M_SHUF:.+]] = cir.vec.shuffle(%{{.+}}, %{{.+}} : !cir.vector<8 x 
!cir.int<s, 1>>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : 
!s32i, #cir.int<3> : !s32i]
+  // CIR: cir.vec.ternary(%[[M_SHUF]], %{{.+}}, %{{.+}}) : !cir.vector<4 x 
!cir.int<s, 1>>, !cir.vector<4 x !s32i>
+
+  // LLVM-LABEL: @test_selectd_128
+  // LLVM: shufflevector <8 x i1> %{{.+}}, <8 x i1> %{{.+}}, <4 x i32> <i32 0, 
i32 1, i32 2, i32 3>
+  // LLVM: select <4 x i1> %{{.+}}, <4 x i32> %{{.+}}, <4 x i32> %{{.+}}
+
+  // OGCG-LABEL: @test_selectd_128
+  // OGCG: select <4 x i1> %{{.+}}, <4 x i32> %{{.+}}, <4 x i32> %{{.+}}
+  return (__m128i)__builtin_ia32_selectd_128(k, (__v4si)a, (__v4si)b);
+}
+
+__m256i test_selectd_256(__mmask8 k, __m256i a, __m256i b) {
+  // CIR-LABEL: @test_selectd_256
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<8 x 
!cir.int<s, 1>>, !cir.vector<8 x !s32i>
+
+  // LLVM-LABEL: @test_selectd_256
+  // LLVM: select <8 x i1> %{{.+}}, <8 x i32> %{{.+}}, <8 x i32> %{{.+}}
+
+  // OGCG-LABEL: @test_selectd_256
+  // OGCG: select <8 x i1> %{{.+}}, <8 x i32> %{{.+}}, <8 x i32> %{{.+}}
+  return (__m256i)__builtin_ia32_selectd_256(k, (__v8si)a, (__v8si)b);
+}
+
+__m512i test_selectd_512(__mmask16 k, __m512i a, __m512i b) {
+  // CIR-LABEL: @test_selectd_512
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<16 x 
!cir.int<s, 1>>, !cir.vector<16 x !s32i>
+
+  // LLVM-LABEL: @test_selectd_512
+  // LLVM: select <16 x i1> %{{.+}}, <16 x i32> %{{.+}}, <16 x i32> %{{.+}}
+
+  // OGCG-LABEL: @test_selectd_512
+  // OGCG: select <16 x i1> %{{.+}}, <16 x i32> %{{.+}}, <16 x i32> %{{.+}}
+  return (__m512i)__builtin_ia32_selectd_512(k, (__v16si)a, (__v16si)b);
+}
+
+__m128i test_selectq_128(__mmask8 k, __m128i a, __m128i b) {
+  // CIR-LABEL: @test_selectq_128
+  // CIR: %[[M_SHUF:.+]] = cir.vec.shuffle(%{{.+}}, %{{.+}} : !cir.vector<8 x 
!cir.int<s, 1>>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i]
+  // CIR: cir.vec.ternary(%[[M_SHUF]], %{{.+}}, %{{.+}}) : !cir.vector<2 x 
!cir.int<s, 1>>, !cir.vector<2 x !s64i>
+
+  // LLVM-LABEL: @test_selectq_128
+  // LLVM: select <2 x i1> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}
+
+  // OGCG-LABEL: @test_selectq_128
+  // OGCG: select <2 x i1> %{{.+}}, <2 x i64> %{{.+}}, <2 x i64> %{{.+}}
+  return __builtin_ia32_selectq_128(k, (__v2di)a, (__v2di)b);
+}
+
+__m256i test_selectq_256(__mmask8 k, __m256i a, __m256i b) {
+  // CIR-LABEL: @test_selectq_256
+  // CIR: %[[M_SHUF:.+]] = cir.vec.shuffle(%{{.+}}, %{{.+}} : !cir.vector<8 x 
!cir.int<s, 1>>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : 
!s32i, #cir.int<3> : !s32i]
+  // CIR: cir.vec.ternary(%[[M_SHUF]], %{{.+}}, %{{.+}}) : !cir.vector<4 x 
!cir.int<s, 1>>, !cir.vector<4 x !s64i>
+
+  // LLVM-LABEL: @test_selectq_256
+  // LLVM: select <4 x i1> %{{.+}}, <4 x i64> %{{.+}}, <4 x i64> %{{.+}}
+
+  // OGCG-LABEL: @test_selectq_256
+  // OGCG: select <4 x i1> %{{.+}}, <4 x i64> %{{.+}}, <4 x i64> %{{.+}}
+  return __builtin_ia32_selectq_256(k, (__v4di)a, (__v4di)b);
+}
+
+__m512i test_selectq_512(__mmask8 k, __m512i a, __m512i b) {
+  // CIR-LABEL: @test_selectq_512
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<8 x 
!cir.int<s, 1>>, !cir.vector<8 x !s64i>
+
+  // LLVM-LABEL: @test_selectq_512
+  // LLVM: select <8 x i1> %{{.+}}, <8 x i64> %{{.+}}, <8 x i64> %{{.+}}
+
+  // OGCG-LABEL: @test_selectq_512
+  // OGCG: select <8 x i1> %{{.+}}, <8 x i64> %{{.+}}, <8 x i64> %{{.+}}
+  return __builtin_ia32_selectq_512(k, (__v8di)a, (__v8di)b);
+}
+
+__m128h test_selectph_128(__mmask8 k, __m128h a, __m128h b) {
+  // CIR-LABEL: @test_selectph_128
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<8 x 
!cir.int<s, 1>>, !cir.vector<8 x !cir.f16>
+
+  // LLVM-LABEL: @test_selectph_128
+  // LLVM: select <8 x i1> %{{.+}}, <8 x half> %{{.+}}, <8 x half> %{{.+}}
+
+  // OGCG-LABEL: @test_selectph_128
+  // OGCG: select <8 x i1> %{{.+}}, <8 x half> %{{.+}}, <8 x half> %{{.+}}
+  return __builtin_ia32_selectph_128(k, (__v8hf)a, (__v8hf)b);
+}
+
+__m256h test_selectph_256(__mmask16 k, __m256h a, __m256h b) {
+  // CIR-LABEL: @test_selectph_256
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<16 x 
!cir.int<s, 1>>, !cir.vector<16 x !cir.f16>
+
+  // LLVM-LABEL: @test_selectph_256
+  // LLVM: select <16 x i1> %{{.+}}, <16 x half> %{{.+}}, <16 x half> %{{.+}}
+
+  // OGCG-LABEL: @test_selectph_256
+  // OGCG: select <16 x i1> %{{.+}}, <16 x half> %{{.+}}, <16 x half> %{{.+}}
+  return __builtin_ia32_selectph_256(k, (__v16hf)a, (__v16hf)b);
+}
+
+__m512h test_selectph_512(__mmask32 k, __m512h a, __m512h b) {
+  // CIR-LABEL: @test_selectph_512
+  // CIR: cir.vec.ternary(%{{.+}}, %{{.+}}, %{{.+}}) : !cir.vector<32 x 
!cir.int<s, 1>>, !cir.vector<32 x !cir.f16>
+
+  // LLVM-LABEL: @test_selectph_512
+  // LLVM: select <32 x i1> %{{.+}}, <32 x half> %{{.+}}, <32 x half> %{{.+}}
+
+  // OGCG-LABEL: @test_selectph_512
+  // OGCG: select <32 x i1> %{{.+}}, <32 x half> %{{.+}}, <32 x half> %{{.+}}
+  return __builtin_ia32_selectph_512(k, (__v32hf)a, (__v32hf)b);
+}
+
+__m128bh test_selectsbf_128(__mmask8 k, __m128bh a, __m128bh b) {
+  // CIR-LABEL: @test_selectsbf_128
+  // CIR: %[[COND:.+]] = cir.cast int_to_bool %{{.+}} : !cir.int<u, 1> -> 
!cir.bool
+  // CIR: cir.select if %[[COND]] then %{{.+}} else %{{.+}} : (!cir.bool, 
!cir.bf16, !cir.bf16) -> !cir.bf16
----------------
andykaylor wrote:

I agree with Copilot's suggestion here. There is quite a bit of logic to get 
the operands for the select instruction, and there is not enough tested here to 
verify that the LLVM IR that we're generating via CIR is equivalent to OGCG.

https://github.com/llvm/llvm-project/pull/174003
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to