Author: Mariya Podchishchaeva Date: 2026-11-11T11:15:33+01:00 New Revision: 4f75128a46440587704cf8b5c950a5d217c3358b
URL: https://github.com/llvm/llvm-project/commit/4f75128a46440587704cf8b5c950a5d217c3358b DIFF: https://github.com/llvm/llvm-project/commit/4f75128a46440587704cf8b5c950a5d217c3358b.diff LOG: [CIR][X86] Add support for cmpps/cmppd* builtins (#228491) This basically ports corresponding OGCG code using `cir.vec.fcmp` instruction and/or intrinsic calls. I used claude to help with testing and mechanical code changes. Added: clang/test/CIR/CodeGenBuiltins/X86/cmp-bf16-builtins.c clang/test/CIR/CodeGenBuiltins/X86/cmp-fp-builtins.c clang/test/CIR/CodeGenBuiltins/X86/cmp-fp16-512-builtins.c Modified: clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp clang/test/CIR/CodeGen/target-features-error-2.c Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp index b46584667bac44..8d440c9277f7af 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp @@ -43,6 +43,92 @@ static mlir::Value emitVectorFCmp(CIRGenFunction &cgf, const CallExpr &expr, return builder.createBitcast(cmp, ops[0].getType()); } +struct X86FCmpInfo { + cir::FCmpOpKind pred; + bool isSignaling; +}; + +/// Decodes comparison condition of x86 cmppps/cmppd* builtins which is an +/// integer in the range [0, 31]. Predicates for 16-31 repeat the 0-15 +/// predicates and diff er only in signaling behavior. +static X86FCmpInfo getX86FCmpInfo(unsigned cc) { + bool inverseSig = cc & 0x10; + const auto createVal = [inverseSig](cir::FCmpOpKind kind, bool isSignaling) { + return X86FCmpInfo{kind, static_cast<bool>(inverseSig ^ isSignaling)}; + }; + switch (cc & 0xf) { + case 0x00: + return createVal(cir::FCmpOpKind::oeq, /*isSignaling=*/false); + case 0x01: + return createVal(cir::FCmpOpKind::olt, /*isSignaling=*/true); + case 0x02: + return createVal(cir::FCmpOpKind::ole, /*isSignaling=*/true); + case 0x03: + return createVal(cir::FCmpOpKind::uno, /*isSignaling=*/false); + case 0x04: + return createVal(cir::FCmpOpKind::une, /*isSignaling=*/false); + case 0x05: + return createVal(cir::FCmpOpKind::uge, /*isSignaling=*/true); + case 0x06: + return createVal(cir::FCmpOpKind::ugt, /*isSignaling=*/true); + case 0x07: + return createVal(cir::FCmpOpKind::ord, /*isSignaling=*/false); + case 0x08: + return createVal(cir::FCmpOpKind::ueq, /*isSignaling=*/false); + case 0x09: + return createVal(cir::FCmpOpKind::ult, /*isSignaling=*/true); + case 0x0a: + return createVal(cir::FCmpOpKind::ule, /*isSignaling=*/true); + case 0x0b: + return createVal(cir::FCmpOpKind::_false, /*isSignaling=*/false); + case 0x0c: + return createVal(cir::FCmpOpKind::one, /*isSignaling=*/false); + case 0x0d: + return createVal(cir::FCmpOpKind::oge, /*isSignaling=*/true); + case 0x0e: + return createVal(cir::FCmpOpKind::ogt, /*isSignaling=*/true); + case 0x0f: + return createVal(cir::FCmpOpKind::_true, /*isSignaling=*/false); + default: + llvm_unreachable("Unhandled cc"); + } +} + +/// Returns the legacy x86 intrinsic that implements the given x86 cmppps/cmppd* +/// builtin. +static llvm::StringRef getX86FCmpIntrinsicName(unsigned builtinID) { + switch (builtinID) { + default: + llvm_unreachable("Unexpected builtin"); + case X86::BI__builtin_ia32_cmpps: + return "x86.sse.cmp.ps"; + case X86::BI__builtin_ia32_cmpps256: + return "x86.avx.cmp.ps.256"; + case X86::BI__builtin_ia32_cmppd: + return "x86.sse2.cmp.pd"; + case X86::BI__builtin_ia32_cmppd256: + return "x86.avx.cmp.pd.256"; + case X86::BI__builtin_ia32_cmpph128_mask: + return "x86.avx512fp16.mask.cmp.ph.128"; + case X86::BI__builtin_ia32_cmpph256_mask: + return "x86.avx512fp16.mask.cmp.ph.256"; + case X86::BI__builtin_ia32_cmpph512_mask: + return "x86.avx512fp16.mask.cmp.ph.512"; + case X86::BI__builtin_ia32_cmpps512_mask: + return "x86.avx512.mask.cmp.ps.512"; + case X86::BI__builtin_ia32_cmppd512_mask: + return "x86.avx512.mask.cmp.pd.512"; + case X86::BI__builtin_ia32_cmpps128_mask: + return "x86.avx512.mask.cmp.ps.128"; + case X86::BI__builtin_ia32_cmpps256_mask: + return "x86.avx512.mask.cmp.ps.256"; + case X86::BI__builtin_ia32_cmppd128_mask: + return "x86.avx512.mask.cmp.pd.128"; + case X86::BI__builtin_ia32_cmppd256_mask: + return "x86.avx512.mask.cmp.pd.256"; + } +} + static mlir::Value getMaskVecValue(CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value mask, unsigned numElems) { auto maskTy = cir::VectorType::getFixed( @@ -1258,6 +1344,7 @@ CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr) { // The operands of the builtin call llvm::SmallVector<mlir::Value> ops; + bool isMaskFCmp = false; // `ICEArguments` is a bitmap indicating whether the argument at the i-th bit // is required to be a constant integer expression. @@ -2893,10 +2980,57 @@ CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID, const CallExpr *expr) { case X86::BI__builtin_ia32_vcmpbf16512_mask: case X86::BI__builtin_ia32_vcmpbf16256_mask: case X86::BI__builtin_ia32_vcmpbf16128_mask: + isMaskFCmp = true; + [[fallthrough]]; case X86::BI__builtin_ia32_cmpps: case X86::BI__builtin_ia32_cmpps256: case X86::BI__builtin_ia32_cmppd: - case X86::BI__builtin_ia32_cmppd256: + case X86::BI__builtin_ia32_cmppd256: { + mlir::Location loc = getLoc(expr->getExprLoc()); + + // The third argument is the comparison condition. + unsigned cc = + ops[2].getDefiningOp<cir::ConstantOp>().getIntValue().getZExtValue() & + 0x1f; + + X86FCmpInfo cmpInfo = getX86FCmpInfo(cc); + + auto opsTy = cast<cir::VectorType>(ops[0].getType()); + unsigned numElts = opsTy.getFixedSize(); + + // If the predicate is true or false, or the builtin is mask enabled, and + // we're using constrained intrinsics, there is no compare operation we can + // use. Just use the legacy X86 specific intrinsic. + if (builder.getIsFPConstrained() && + (cmpInfo.pred == cir::FCmpOpKind::_true || + cmpInfo.pred == cir::FCmpOpKind::_false || isMaskFCmp)) { + llvm::StringRef intrinsicName = getX86FCmpIntrinsicName(builtinID); + + if (isMaskFCmp) { + ops[3] = getMaskVecValue(builder, loc, ops[3], numElts); + mlir::Value cmp = builder.emitIntrinsicCallOp( + loc, intrinsicName, + cir::VectorType::getFixed(builder.getSIntNTy(1), numElts), ops); + return emitX86MaskedCompareResult(builder, cmp, numElts, nullptr, loc); + } + + return builder.emitIntrinsicCallOp(loc, intrinsicName, ops[0].getType(), + ops); + } + + unsigned width = builder.getCIRIntOrFloatBitWidth(opsTy.getElementType()); + cir::IntType cmpEltTy = builder.getSIntNTy(isMaskFCmp ? 1 : width); + auto cmpTy = cir::VectorType::getFixed(cmpEltTy, numElts); + + CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(*this, expr); + mlir::Value cmp = builder.createVecFCompare( + loc, cmpTy, cmpInfo.pred, ops[0], ops[1], cmpInfo.isSignaling); + + if (isMaskFCmp) + return emitX86MaskedCompareResult(builder, cmp, numElts, ops[3], loc); + + return builder.createBitcast(cmp, opsTy); + } case X86::BI__builtin_ia32_cmpeqss: case X86::BI__builtin_ia32_cmpltss: case X86::BI__builtin_ia32_cmpless: diff --git a/clang/test/CIR/CodeGen/target-features-error-2.c b/clang/test/CIR/CodeGen/target-features-error-2.c index 6891e6c73a4e20..a467c1891963b5 100644 --- a/clang/test/CIR/CodeGen/target-features-error-2.c +++ b/clang/test/CIR/CodeGen/target-features-error-2.c @@ -17,8 +17,6 @@ int baz(__m256i a) { #if NEED_AVX_2 __m128 need_avx(__m128 a, __m128 b) { - // expected-error@+2{{unimplemented X86 builtin call:}} - // expected-error@+1{{unimplemented builtin call:}} return _mm_cmp_ps(a, b, 8); // expected-error {{'__builtin_ia32_cmpps' needs target feature avx}} } #endif diff --git a/clang/test/CIR/CodeGenBuiltins/X86/cmp-bf16-builtins.c b/clang/test/CIR/CodeGenBuiltins/X86/cmp-bf16-builtins.c new file mode 100644 index 00000000000000..85b2f90ae7c996 --- /dev/null +++ b/clang/test/CIR/CodeGenBuiltins/X86/cmp-bf16-builtins.c @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx10.2 -fclangir -emit-cir -o %t.cir -Wall -Werror +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx10.2 -fclangir -emit-llvm -o %t.ll -Wall -Werror +// RUN: FileCheck --check-prefix=CHECK --input-file=%t.ll %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx10.2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK + +// Strict FP is not tested: classic codegen hits an unreachable for the bf16 +// compare builtins under -ffp-exception-behavior=strict. + +#include <immintrin.h> + +__mmask8 test_mm_cmp_pbh_mask(__m128bh a, __m128bh b) { + // CIR-LABEL: cir.func {{.*}}@test_mm_cmp_pbh_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.bf16>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm_cmp_pbh_mask + // CHECK: %[[CMP:.*]] = fcmp olt <8 x bfloat> %{{.*}}, %{{.*}} + // CHECK: bitcast <8 x i1> %[[CMP]] to i8 + return _mm_cmp_pbh_mask(a, b, _CMP_LT_OS); +} + +__mmask16 test_mm256_cmp_pbh_mask(__m256bh a, __m256bh b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_cmp_pbh_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<16 x !cir.bf16>, !cir.vector<16 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm256_cmp_pbh_mask + // CHECK: %[[CMP:.*]] = fcmp olt <16 x bfloat> %{{.*}}, %{{.*}} + // CHECK: bitcast <16 x i1> %[[CMP]] to i16 + return _mm256_cmp_pbh_mask(a, b, _CMP_LT_OS); +} + +__mmask32 test_mm512_cmp_pbh_mask(__m512bh a, __m512bh b) { + // CIR-LABEL: cir.func {{.*}}@test_mm512_cmp_pbh_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<32 x !cir.bf16>, !cir.vector<32 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm512_cmp_pbh_mask + // CHECK: %[[CMP:.*]] = fcmp olt <32 x bfloat> %{{.*}}, %{{.*}} + // CHECK: bitcast <32 x i1> %[[CMP]] to i32 + return _mm512_cmp_pbh_mask(a, b, _CMP_LT_OS); +} diff --git a/clang/test/CIR/CodeGenBuiltins/X86/cmp-fp-builtins.c b/clang/test/CIR/CodeGenBuiltins/X86/cmp-fp-builtins.c new file mode 100644 index 00000000000000..743ae34caa7175 --- /dev/null +++ b/clang/test/CIR/CodeGenBuiltins/X86/cmp-fp-builtins.c @@ -0,0 +1,392 @@ +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -fclangir -emit-cir -o %t.cir -Wall -Werror +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -fclangir -emit-llvm -o %t.ll -Wall -Werror +// RUN: FileCheck --check-prefix=CHECK --input-file=%t.ll %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK + +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -ffp-exception-behavior=strict -fexperimental-strict-floating-point -fclangir -emit-cir -o %t.strict.cir -Wall -Werror +// RUN: FileCheck --check-prefix=CIR-STRICT --input-file=%t.strict.cir %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -ffp-exception-behavior=strict -fexperimental-strict-floating-point -fclangir -emit-llvm -o %t.strict.ll -Wall -Werror +// RUN: FileCheck --check-prefix=CHECK-STRICT --input-file=%t.strict.ll %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK-STRICT + +#include <immintrin.h> + +__m128 test_cmp_ps_eq_oq(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_eq_oq + // CIR: %[[CMP:.*]] = cir.vec.fcmp(oeq, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_eq_oq + // CIR-STRICT: cir.vec.fcmp(oeq, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> fenv<{{.*}}strict_except = true> + + // CHECK-LABEL: @test_cmp_ps_eq_oq + // CHECK: %[[CMP:.*]] = fcmp oeq <4 x float> %{{.*}}, %{{.*}} + // CHECK: %[[SEXT:.*]] = sext <4 x i1> %[[CMP]] to <4 x i32> + // CHECK: bitcast <4 x i32> %[[SEXT]] to <4 x float> + + // CHECK-STRICT-LABEL: @test_cmp_ps_eq_oq + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"oeq", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_EQ_OQ); +} + +// EQ_OS is signaling although eq is quiet by default. +__m128 test_cmp_ps_eq_os(__m128 a, __m128 b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_eq_os + // CIR-STRICT: cir.vec.fcmp(oeq, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> signaling fenv<{{.*}}strict_except = true> + + // CHECK-STRICT-LABEL: @test_cmp_ps_eq_os + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmps.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"oeq", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_EQ_OS); +} + +// LT_OQ is quiet although lt is signaling by default. +__m256d test_cmp_pd_lt_oq(__m256d a, __m256d b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_pd_lt_oq + // CIR-STRICT: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.double>, !cir.vector<4 x !s64i> fenv<{{.*}}strict_except = true> + + // CHECK-STRICT-LABEL: @test_cmp_pd_lt_oq + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmp.v4f64(<4 x double> %{{.*}}, <4 x double> %{{.*}}, metadata !"olt", metadata !"fpexcept.strict") + return _mm256_cmp_pd(a, b, _CMP_LT_OQ); +} + +__m128 test_cmp_ps_nlt_us(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_nlt_us + // CIR: %[[CMP:.*]] = cir.vec.fcmp(uge, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_nlt_us + // CHECK: %[[CMP:.*]] = fcmp uge <4 x float> %{{.*}}, %{{.*}} + // CHECK: sext <4 x i1> %[[CMP]] to <4 x i32> + + // CHECK-STRICT-LABEL: @test_cmp_ps_nlt_us + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmps.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"uge", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_NLT_US); +} + +// FALSE and TRUE +__m128 test_cmp_ps_false_oq(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_false_oq + // CIR: %[[CMP:.*]] = cir.vec.fcmp(false, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_false_oq + // CHECK: fcmp false <4 x float> %{{.*}}, %{{.*}} + + // Under strict FP there is no compare to use, so the target intrinsic is + // called. + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_false_oq + // CIR-STRICT: cir.call_llvm_intrinsic "x86.sse.cmp.ps" + + // CHECK-STRICT-LABEL: @test_cmp_ps_false_oq + // CHECK-STRICT: call <4 x float> @llvm.x86.sse.cmp.ps(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i8 11) + return _mm_cmp_ps(a, b, _CMP_FALSE_OQ); +} + +__m128 test_cmp_ps_true_uq(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_true_uq + // CIR: %[[CMP:.*]] = cir.vec.fcmp(true, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_true_uq + // CHECK: fcmp true <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_TRUE_UQ); +} + +// Masked compares. +__mmask8 test_mm256_mask_cmp_ps_mask(__mmask8 m, __m256 a, __m256 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_mask_cmp_ps_mask + // CIR: %[[CMP:.*]] = cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.float>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.and + + // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask + // CHECK: %[[CMP:.*]] = fcmp olt <8 x float> %{{.*}}, %{{.*}} + // CHECK: %[[MASK:.*]] = bitcast i8 %{{.*}} to <8 x i1> + // CHECK: and <8 x i1> %[[CMP]], %[[MASK]] + + // CHECK-STRICT-LABEL: @test_mm256_mask_cmp_ps_mask + // CHECK-STRICT: call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256(<8 x float> %{{.*}}, <8 x float> %{{.*}}, i32 1, <8 x i1> %{{.*}}) + return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_LT_OS); +} + +// Remaining non-signaling-flipped predicates. +__m128 test_cmp_ps_lt_os(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_lt_os + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_lt_os + // CHECK: fcmp olt <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_LT_OS); +} + +__m128 test_cmp_ps_le_os(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_le_os + // CIR: cir.vec.fcmp(ole, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_le_os + // CHECK: fcmp ole <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_LE_OS); +} + +__m128 test_cmp_ps_unord_q(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_unord_q + // CIR: cir.vec.fcmp(uno, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_unord_q + // CHECK: fcmp uno <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_UNORD_Q); +} + +__m128 test_cmp_ps_neq_uq(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_neq_uq + // CIR: cir.vec.fcmp(une, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_neq_uq + // CHECK: fcmp une <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_NEQ_UQ); +} + +__m128 test_cmp_ps_nle_us(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_nle_us + // CIR: %[[CMP:.*]] = cir.vec.fcmp(ugt, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_nle_us + // CHECK: %[[CMP:.*]] = fcmp ugt <4 x float> %{{.*}}, %{{.*}} + // CHECK: sext <4 x i1> %[[CMP]] to <4 x i32> + return _mm_cmp_ps(a, b, _CMP_NLE_US); +} + +__m128 test_cmp_ps_ord_q(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_ord_q + // CIR: %[[CMP:.*]] = cir.vec.fcmp(ord, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_ord_q + // CHECK: %[[CMP:.*]] = fcmp ord <4 x float> %{{.*}}, %{{.*}} + // CHECK: sext <4 x i1> %[[CMP]] to <4 x i32> + return _mm_cmp_ps(a, b, _CMP_ORD_Q); +} + +__m128 test_cmp_ps_eq_uq(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_eq_uq + // CIR: %[[CMP:.*]] = cir.vec.fcmp(ueq, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_eq_uq + // CHECK: %[[CMP:.*]] = fcmp ueq <4 x float> %{{.*}}, %{{.*}} + // CHECK: sext <4 x i1> %[[CMP]] to <4 x i32> + return _mm_cmp_ps(a, b, _CMP_EQ_UQ); +} + +__m128 test_cmp_ps_nge_us(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_nge_us + // CIR: %[[CMP:.*]] = cir.vec.fcmp(ult, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_nge_us + // CHECK: %[[CMP:.*]] = fcmp ult <4 x float> %{{.*}}, %{{.*}} + // CHECK: sext <4 x i1> %[[CMP]] to <4 x i32> + return _mm_cmp_ps(a, b, _CMP_NGE_US); +} + +__m128 test_cmp_ps_ngt_us(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_ngt_us + // CIR: %[[CMP:.*]] = cir.vec.fcmp(ule, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + // CIR: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps_ngt_us + // CHECK: %[[CMP:.*]] = fcmp ule <4 x float> %{{.*}}, %{{.*}} + // CHECK: sext <4 x i1> %[[CMP]] to <4 x i32> + return _mm_cmp_ps(a, b, _CMP_NGT_US); +} + +__m128 test_cmp_ps_neq_oq(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_neq_oq + // CIR: cir.vec.fcmp(one, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_neq_oq + // CHECK: fcmp one <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_NEQ_OQ); +} + +__m128 test_cmp_ps_ge_os(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_ge_os + // CIR: cir.vec.fcmp(oge, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_ge_os + // CHECK: fcmp oge <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_GE_OS); +} + +__m128 test_cmp_ps_gt_os(__m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps_gt_os + // CIR: cir.vec.fcmp(ogt, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> + + // CHECK-LABEL: @test_cmp_ps_gt_os + // CHECK: fcmp ogt <4 x float> %{{.*}}, %{{.*}} + return _mm_cmp_ps(a, b, _CMP_GT_OS); +} + +// Predicates 16-31 flip the signaling behavior of predicates 0-15. +__m128 test_cmp_ps_neq_us(__m128 a, __m128 b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_neq_us + // CIR-STRICT: cir.vec.fcmp(une, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> signaling fenv<{{.*}}strict_except = true> + + // CHECK-STRICT-LABEL: @test_cmp_ps_neq_us + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmps.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"une", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_NEQ_US); +} + +__m128 test_cmp_ps_unord_s(__m128 a, __m128 b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_unord_s + // CIR-STRICT: cir.vec.fcmp(uno, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> signaling fenv<{{.*}}strict_except = true> + + // CHECK-STRICT-LABEL: @test_cmp_ps_unord_s + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmps.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"uno", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_UNORD_S); +} + +__m128 test_cmp_ps_ge_oq(__m128 a, __m128 b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_ge_oq + // CIR-STRICT: cir.vec.fcmp(oge, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> fenv<{{.*}}strict_except = true> + + // CHECK-STRICT-LABEL: @test_cmp_ps_ge_oq + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"oge", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_GE_OQ); +} + +__m128 test_cmp_ps_nge_uq(__m128 a, __m128 b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_nge_uq + // CIR-STRICT: %[[CMP:.*]] = cir.vec.fcmp(ult, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> fenv<{{.*}}strict_except = true> + // CIR-STRICT: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-STRICT-LABEL: @test_cmp_ps_nge_uq + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"ult", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_NGE_UQ); +} + +__m128 test_cmp_ps_ord_s(__m128 a, __m128 b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_ps_ord_s + // CIR-STRICT: %[[CMP:.*]] = cir.vec.fcmp(ord, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> signaling fenv<{{.*}}strict_except = true> + // CIR-STRICT: cir.cast bitcast %[[CMP]] : !cir.vector<4 x !s32i> -> !cir.vector<4 x !cir.float> + + // CHECK-STRICT-LABEL: @test_cmp_ps_ord_s + // CHECK-STRICT: call <4 x i1> @llvm.experimental.constrained.fcmps.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, metadata !"ord", metadata !"fpexcept.strict") + return _mm_cmp_ps(a, b, _CMP_ORD_S); +} + +__m128d test_cmp_pd_lt_os(__m128d a, __m128d b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_pd_lt_os + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<2 x !cir.double>, !cir.vector<2 x !s64i> + // CIR: cir.cast bitcast %{{.*}} : !cir.vector<2 x !s64i> -> !cir.vector<2 x !cir.double> + + // CHECK-LABEL: @test_cmp_pd_lt_os + // CHECK: fcmp olt <2 x double> %{{.*}}, %{{.*}} + return _mm_cmp_pd(a, b, _CMP_LT_OS); +} + +__m256 test_cmp_ps256_le_os(__m256 a, __m256 b) { + // CIR-LABEL: cir.func {{.*}}@test_cmp_ps256_le_os + // CIR: cir.vec.fcmp(ole, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.float>, !cir.vector<8 x !s32i> + // CIR: cir.cast bitcast %{{.*}} : !cir.vector<8 x !s32i> -> !cir.vector<8 x !cir.float> + + // CHECK-LABEL: @test_cmp_ps256_le_os + // CHECK: fcmp ole <8 x float> %{{.*}}, %{{.*}} + return _mm256_cmp_ps(a, b, _CMP_LE_OS); +} + +__m128d test_cmp_pd_true_us_strict(__m128d a, __m128d b) { + // CIR-STRICT-LABEL: cir.func {{.*}}@test_cmp_pd_true_us_strict + // CIR-STRICT: cir.call_llvm_intrinsic "x86.sse2.cmp.pd" + + // CHECK-STRICT-LABEL: @test_cmp_pd_true_us_strict + // CHECK-STRICT: call <2 x double> @llvm.x86.sse2.cmp.pd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i8 31) + return _mm_cmp_pd(a, b, _CMP_TRUE_US); +} + +__mmask8 test_mm_mask_cmp_ps_mask(__mmask8 m, __m128 a, __m128 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm_mask_cmp_ps_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !cir.int<s, 1>> + // CIR: cir.and + // CIR: cir.vec.shuffle + + // CHECK-LABEL: @test_mm_mask_cmp_ps_mask + // CHECK: fcmp olt <4 x float> %{{.*}}, %{{.*}} + // CHECK: and <4 x i1> + // CHECK: shufflevector <4 x i1> + return _mm_mask_cmp_ps_mask(m, a, b, _CMP_LT_OS); +} + +__mmask8 test_mm_mask_cmp_pd_mask(__mmask8 m, __m128d a, __m128d b) { + // CIR-LABEL: cir.func {{.*}}@test_mm_mask_cmp_pd_mask + // CIR: cir.vec.fcmp(ole, %{{.*}}, %{{.*}}) : !cir.vector<2 x !cir.double>, !cir.vector<2 x !cir.int<s, 1>> + // CIR: cir.and + + // CHECK-LABEL: @test_mm_mask_cmp_pd_mask + // CHECK: fcmp ole <2 x double> %{{.*}}, %{{.*}} + // CHECK: and <2 x i1> + return _mm_mask_cmp_pd_mask(m, a, b, _CMP_LE_OS); +} + +__mmask8 test_mm256_mask_cmp_pd_mask(__mmask8 m, __m256d a, __m256d b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_mask_cmp_pd_mask + // CIR: cir.vec.fcmp(ogt, %{{.*}}, %{{.*}}) : !cir.vector<4 x !cir.double>, !cir.vector<4 x !cir.int<s, 1>> + // CIR: cir.and + + // CHECK-LABEL: @test_mm256_mask_cmp_pd_mask + // CHECK: fcmp ogt <4 x double> %{{.*}}, %{{.*}} + // CHECK: and <4 x i1> + return _mm256_mask_cmp_pd_mask(m, a, b, _CMP_GT_OS); +} + +__mmask8 test_mm256_cmp_ps_mask(__m256 a, __m256 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_cmp_ps_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.float>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm256_cmp_ps_mask + // CHECK: %[[CMP:.*]] = fcmp olt <8 x float> %{{.*}}, %{{.*}} + // CHECK: bitcast <8 x i1> %[[CMP]] to i8 + return _mm256_cmp_ps_mask(a, b, _CMP_LT_OS); +} + +__mmask8 test_mm256_mask_cmp_ps_mask_false(__mmask8 m, __m256 a, __m256 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_mask_cmp_ps_mask_false + // CIR: %[[CMP:.*]] = cir.vec.fcmp(false, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.float>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.and %[[CMP]], %{{.*}} + + // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask_false + // CHECK: %[[CMP:.*]] = fcmp false <8 x float> %{{.*}}, %{{.*}} + // CHECK: and <8 x i1> %[[CMP]], %{{.*}} + return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_FALSE_OQ); +} + +__mmask8 test_mm256_mask_cmp_ps_mask_true(__mmask8 m, __m256 a, __m256 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_mask_cmp_ps_mask_true + // CIR: %[[CMP:.*]] = cir.vec.fcmp(true, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.float>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.and %[[CMP]], %{{.*}} + + // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask_true + // CHECK: %[[CMP:.*]] = fcmp true <8 x float> %{{.*}}, %{{.*}} + // CHECK: and <8 x i1> %[[CMP]], %{{.*}} + + // Under strict FP the target intrinsic is called. + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm256_mask_cmp_ps_mask_true + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512.mask.cmp.ps.256" + + // CHECK-STRICT-LABEL: @test_mm256_mask_cmp_ps_mask_true + // CHECK-STRICT: call <8 x i1> @llvm.x86.avx512.mask.cmp.ps.256(<8 x float> %{{.*}}, <8 x float> %{{.*}}, i32 15, <8 x i1> %{{.*}}) + return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_TRUE_UQ); +} + +__mmask8 test_mm256_mask_cmp_ps_mask_nlt_us(__mmask8 m, __m256 a, __m256 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_mask_cmp_ps_mask_nlt_us + // CIR: %[[CMP:.*]] = cir.vec.fcmp(uge, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.float>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.and %[[CMP]], %{{.*}} + + // CHECK-LABEL: @test_mm256_mask_cmp_ps_mask_nlt_us + // CHECK: %[[CMP:.*]] = fcmp uge <8 x float> %{{.*}}, %{{.*}} + // CHECK: and <8 x i1> %[[CMP]], %{{.*}} + return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_NLT_US); +} diff --git a/clang/test/CIR/CodeGenBuiltins/X86/cmp-fp16-512-builtins.c b/clang/test/CIR/CodeGenBuiltins/X86/cmp-fp16-512-builtins.c new file mode 100644 index 00000000000000..6d4722912d47c5 --- /dev/null +++ b/clang/test/CIR/CodeGenBuiltins/X86/cmp-fp16-512-builtins.c @@ -0,0 +1,117 @@ +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -fclangir -emit-cir -o %t.cir -Wall -Werror +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -fclangir -emit-llvm -o %t.ll -Wall -Werror +// RUN: FileCheck --check-prefix=CHECK --input-file=%t.ll %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK + +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -ffp-exception-behavior=strict -fexperimental-strict-floating-point -fclangir -emit-cir -o %t.strict.cir -Wall -Werror +// RUN: FileCheck --check-prefix=CIR-STRICT --input-file=%t.strict.cir %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -ffp-exception-behavior=strict -fexperimental-strict-floating-point -fclangir -emit-llvm -o %t.strict.ll -Wall -Werror +// RUN: FileCheck --check-prefix=CHECK-STRICT --input-file=%t.strict.ll %s +// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefix=CHECK-STRICT + +#include <immintrin.h> + +__mmask8 test_mm_cmp_ph_mask(__m128h a, __m128h b) { + // CIR-LABEL: cir.func {{.*}}@test_mm_cmp_ph_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.f16>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm_cmp_ph_mask + // CHECK: %[[CMP:.*]] = fcmp olt <8 x half> %{{.*}}, %{{.*}} + // CHECK: bitcast <8 x i1> %[[CMP]] to i8 + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm_cmp_ph_mask + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512fp16.mask.cmp.ph.128" + + // CHECK-STRICT-LABEL: @test_mm_cmp_ph_mask + // CHECK-STRICT: call <8 x i1> @llvm.x86.avx512fp16.mask.cmp.ph.128(<8 x half> %{{.*}}, <8 x half> %{{.*}}, i32 1, <8 x i1> splat (i1 true)) + return _mm_cmp_ph_mask(a, b, _CMP_LT_OS); +} + +__mmask16 test_mm256_cmp_ph_mask(__m256h a, __m256h b) { + // CIR-LABEL: cir.func {{.*}}@test_mm256_cmp_ph_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<16 x !cir.f16>, !cir.vector<16 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm256_cmp_ph_mask + // CHECK: %[[CMP:.*]] = fcmp olt <16 x half> %{{.*}}, %{{.*}} + // CHECK: bitcast <16 x i1> %[[CMP]] to i16 + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm256_cmp_ph_mask + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512fp16.mask.cmp.ph.256" + + // CHECK-STRICT-LABEL: @test_mm256_cmp_ph_mask + // CHECK-STRICT: call <16 x i1> @llvm.x86.avx512fp16.mask.cmp.ph.256(<16 x half> %{{.*}}, <16 x half> %{{.*}}, i32 1, <16 x i1> splat (i1 true)) + return _mm256_cmp_ph_mask(a, b, _CMP_LT_OS); +} + +__mmask32 test_mm512_cmp_ph_mask(__m512h a, __m512h b) { + // CIR-LABEL: cir.func {{.*}}@test_mm512_cmp_ph_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<32 x !cir.f16>, !cir.vector<32 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm512_cmp_ph_mask + // CHECK: %[[CMP:.*]] = fcmp olt <32 x half> %{{.*}}, %{{.*}} + // CHECK: bitcast <32 x i1> %[[CMP]] to i32 + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm512_cmp_ph_mask + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512fp16.mask.cmp.ph.512" + + // CHECK-STRICT-LABEL: @test_mm512_cmp_ph_mask + // CHECK-STRICT: call <32 x i1> @llvm.x86.avx512fp16.mask.cmp.ph.512(<32 x half> %{{.*}}, <32 x half> %{{.*}}, i32 1, <32 x i1> splat (i1 true), i32 4) + return _mm512_cmp_ph_mask(a, b, _CMP_LT_OS); +} + +__mmask16 test_mm512_cmp_ps_mask(__m512 a, __m512 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm512_cmp_ps_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<16 x !cir.float>, !cir.vector<16 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm512_cmp_ps_mask + // CHECK: %[[CMP:.*]] = fcmp olt <16 x float> %{{.*}}, %{{.*}} + // CHECK: bitcast <16 x i1> %[[CMP]] to i16 + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm512_cmp_ps_mask + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512.mask.cmp.ps.512" + + // CHECK-STRICT-LABEL: @test_mm512_cmp_ps_mask + // CHECK-STRICT: call <16 x i1> @llvm.x86.avx512.mask.cmp.ps.512(<16 x float> %{{.*}}, <16 x float> %{{.*}}, i32 1, <16 x i1> splat (i1 true), i32 4) + return _mm512_cmp_ps_mask(a, b, _CMP_LT_OS); +} + +__mmask8 test_mm512_cmp_pd_mask(__m512d a, __m512d b) { + // CIR-LABEL: cir.func {{.*}}@test_mm512_cmp_pd_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<8 x !cir.double>, !cir.vector<8 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm512_cmp_pd_mask + // CHECK: %[[CMP:.*]] = fcmp olt <8 x double> %{{.*}}, %{{.*}} + // CHECK: bitcast <8 x i1> %[[CMP]] to i8 + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm512_cmp_pd_mask + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512.mask.cmp.pd.512" + + // CHECK-STRICT-LABEL: @test_mm512_cmp_pd_mask + // CHECK-STRICT: call <8 x i1> @llvm.x86.avx512.mask.cmp.pd.512(<8 x double> %{{.*}}, <8 x double> %{{.*}}, i32 1, <8 x i1> splat (i1 true), i32 4) + return _mm512_cmp_pd_mask(a, b, _CMP_LT_OS); +} + +// The explicit rounding/SAE argument is passed through to the intrinsic only +// under strict FP. +__mmask16 test_mm512_cmp_round_ps_mask(__m512 a, __m512 b) { + // CIR-LABEL: cir.func {{.*}}@test_mm512_cmp_round_ps_mask + // CIR: cir.vec.fcmp(olt, %{{.*}}, %{{.*}}) : !cir.vector<16 x !cir.float>, !cir.vector<16 x !cir.int<s, 1>> + // CIR: cir.cast bitcast + + // CHECK-LABEL: @test_mm512_cmp_round_ps_mask + // CHECK: %[[CMP:.*]] = fcmp olt <16 x float> %{{.*}}, %{{.*}} + // CHECK: bitcast <16 x i1> %[[CMP]] to i16 + + // CIR-STRICT-LABEL: cir.func {{.*}}@test_mm512_cmp_round_ps_mask + // CIR-STRICT: cir.call_llvm_intrinsic "x86.avx512.mask.cmp.ps.512" + + // CHECK-STRICT-LABEL: @test_mm512_cmp_round_ps_mask + // CHECK-STRICT: call <16 x i1> @llvm.x86.avx512.mask.cmp.ps.512(<16 x float> %{{.*}}, <16 x float> %{{.*}}, i32 1, <16 x i1> splat (i1 true), i32 8) + return _mm512_cmp_round_ps_mask(a, b, _CMP_LT_OS, _MM_FROUND_NO_EXC); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
