Author: Mariya Podchishchaeva Date: 2026-11-12T12:59:31+01:00 New Revision: b02e25dc58dc147d625fa0cb162576eb137b144f
URL: https://github.com/llvm/llvm-project/commit/b02e25dc58dc147d625fa0cb162576eb137b144f DIFF: https://github.com/llvm/llvm-project/commit/b02e25dc58dc147d625fa0cb162576eb137b144f.diff LOG: [CIR] Use `cir.vec.fcmp` op for AArch64 builtins (#241404) I've been splitting integer and floating comparisons and stumbled upon these. claude updated the test. Added: Modified: clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp clang/test/CodeGen/AArch64/neon/intrinsics.c Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp index 9f9b34f80ec3ef..a89c5b6fe7e2a6 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp @@ -625,10 +625,11 @@ emitCommonNeonSISDBuiltinExpr(CIRGenFunction &cgf, //===----------------------------------------------------------------------===// // Emit-helpers //===----------------------------------------------------------------------===// +template <typename CmpKindTy> static mlir::Value emitAArch64CompareBuiltinExpr(CIRGenFunction &cgf, CIRGenBuilderTy &builder, mlir::Location loc, mlir::Value src, - mlir::Type retTy, const cir::CmpOpKind kind) { + mlir::Type retTy, const CmpKindTy kind) { bool scalarCmp = !isa<cir::VectorType>(src.getType()); if (!scalarCmp) { @@ -640,17 +641,28 @@ emitAArch64CompareBuiltinExpr(CIRGenFunction &cgf, CIRGenBuilderTy &builder, mlir::Value zero = builder.getNullValue(src.getType(), loc); - if (!scalarCmp) - return builder.createVecCompare(loc, kind, src, zero); + if (!scalarCmp) { + if constexpr (std::is_same<CmpKindTy, cir::FCmpOpKind>::value) + return builder.createVecFCompare(loc, kind, src, zero); + else + return builder.createVecCompare(loc, kind, src, zero); + } - // For scalars, cast !cir.bool to !cir.int<s, 1> so that the compare - // result is sign- rather zero-extended when casting to the output - // retType. - mlir::Value cmp = builder.createCast( - loc, cir::CastKind::bool_to_int, - builder.createCompare(loc, kind, src, zero), builder.getSIntNTy(1)); + // FIXME FCmpOpKind is only supported for vector comparisons now, modify the + // if when scalar comparisons are supported too; + if constexpr (std::is_same<CmpKindTy, cir::CmpOpKind>::value) { + // For scalars, cast !cir.bool to !cir.int<s, 1> so that the compare + // result is sign- rather zero-extended when casting to the output + // retType. + mlir::Value cmp = builder.createCast( + loc, cir::CastKind::bool_to_int, + builder.createCompare(loc, kind, src, zero), builder.getSIntNTy(1)); + + return builder.createCast(loc, cir::CastKind::integral, cmp, retTy); + } - return builder.createCast(loc, cir::CastKind::integral, cmp, retTy); + llvm_unreachable("Should not end up here"); + return {}; } static cir::VectorType getNeonType(CIRGenFunction *cgf, NeonTypeFlags typeFlags, @@ -887,6 +899,7 @@ static mlir::Value emitCommonNeonBuiltinExpr( const bool hasLegalHalfType = cgf.getTarget().hasFastHalfType(); const bool usgn = neonType.isUnsigned(); const bool isQuad = neonType.isQuad(); + const bool floating = neonType.isFloatingPoint(); // The value of allowBFloatArgsAndRet is true for AArch64, but it should // come from ABI info. @@ -994,6 +1007,9 @@ static mlir::Value emitCommonNeonBuiltinExpr( return mlir::Value{}; case NEON::BI__builtin_neon_vceqz_v: case NEON::BI__builtin_neon_vceqzq_v: + if (floating) + return emitAArch64CompareBuiltinExpr(cgf, cgf.getBuilder(), loc, ops[0], + vTy, cir::FCmpOpKind::oeq); return emitAArch64CompareBuiltinExpr(cgf, cgf.getBuilder(), loc, ops[0], vTy, cir::CmpOpKind::eq); case NEON::BI__builtin_neon_vcgez_v: diff --git a/clang/test/CodeGen/AArch64/neon/intrinsics.c b/clang/test/CodeGen/AArch64/neon/intrinsics.c index f2b00998ad3fe8..5d699610e62265 100644 --- a/clang/test/CodeGen/AArch64/neon/intrinsics.c +++ b/clang/test/CodeGen/AArch64/neon/intrinsics.c @@ -1664,7 +1664,7 @@ uint64x2_t test_vceqzq_u64(uint64x2_t a) { uint32x2_t test_vceqz_f32(float32x2_t a) { // CIR: cir.cast bitcast {{%.*}} : !cir.vector<8 x !s8i> -> !cir.vector<2 x !cir.float> // CIR: [[C_0:%.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.float> -// CIR: cir.vec.cmp(eq, {{%.*}}, [[C_0]]) : !cir.vector<2 x !cir.float>, !cir.vector<2 x !s32i> +// CIR: cir.vec.fcmp(oeq, {{%.*}}, [[C_0]]) : !cir.vector<2 x !cir.float>, !cir.vector<2 x !s32i> // LLVM-SAME: <2 x float> {{.*}} [[A:%.*]]) #[[ATTR0]] { // LLVM: [[TMP0:%.*]] = bitcast <2 x float> [[A]] to <2 x i32> @@ -1681,7 +1681,7 @@ uint32x2_t test_vceqz_f32(float32x2_t a) { uint64x1_t test_vceqz_f64(float64x1_t a) { // CIR: cir.cast bitcast {{%.*}} : !cir.vector<8 x !s8i> -> !cir.vector<1 x !cir.double> // CIR: [[C_0:%.*]] = cir.const #cir.zero : !cir.vector<1 x !cir.double> -// CIR: cir.vec.cmp(eq, {{%.*}}, [[C_0]]) : !cir.vector<1 x !cir.double>, !cir.vector<1 x !s64i> +// CIR: cir.vec.fcmp(oeq, {{%.*}}, [[C_0]]) : !cir.vector<1 x !cir.double>, !cir.vector<1 x !s64i> // LLVM-SAME: <1 x double> {{.*}} [[A:%.*]]) #[[ATTR0]] { // LLVM: [[TMP0:%.*]] = bitcast <1 x double> [[A]] to i64 @@ -1699,7 +1699,7 @@ uint64x1_t test_vceqz_f64(float64x1_t a) { uint32x4_t test_vceqzq_f32(float32x4_t a) { // CIR: cir.cast bitcast {{%.*}} : !cir.vector<16 x !s8i> -> !cir.vector<4 x !cir.float> // CIR: [[C_0:%.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.float> -// CIR: cir.vec.cmp(eq, {{%.*}}, [[C_0]]) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> +// CIR: cir.vec.fcmp(oeq, {{%.*}}, [[C_0]]) : !cir.vector<4 x !cir.float>, !cir.vector<4 x !s32i> // LLVM-SAME: <4 x float> {{.*}} [[A:%.*]]) #[[ATTR0]] { // LLVM: [[TMP0:%.*]] = bitcast <4 x float> [[A]] to <4 x i32> @@ -1716,7 +1716,7 @@ uint32x4_t test_vceqzq_f32(float32x4_t a) { uint64x2_t test_vceqzq_f64(float64x2_t a) { // CIR: cir.cast bitcast {{%.*}} : !cir.vector<16 x !s8i> -> !cir.vector<2 x !cir.double> // CIR: [[C_0:%.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double> -// CIR: cir.vec.cmp(eq, {{%.*}}, [[C_0]]) : !cir.vector<2 x !cir.double>, !cir.vector<2 x !s64i> +// CIR: cir.vec.fcmp(oeq, {{%.*}}, [[C_0]]) : !cir.vector<2 x !cir.double>, !cir.vector<2 x !s64i> // LLVM-SAME: <2 x double> {{.*}} [[A:%.*]]) #[[ATTR0]] { // LLVM: [[TMP0:%.*]] = bitcast <2 x double> [[A]] to <2 x i64> _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
