Skip to content

Commit 9c4435d

Browse files
committed
[CIR][CIRGen] Builtins: focus on non fast math path
The LLVM lowering actually maps to the version without fast math, to add support for fast math we need to set the proper LLVM attribute on each of those operations.
1 parent 90e8feb commit 9c4435d

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ struct MissingFeatures {
114114

115115
// Fast math.
116116
static bool fastMathGuard() { return false; }
117+
// Should be implemented with a moduleOp level attribute and directly
118+
// mapped to LLVM - those can be set directly for every relevant LLVM IR
119+
// dialect operation (log10, ...).
117120
static bool fastMathFlags() { return false; }
118121
static bool fastMathFuncAttributes() { return false; }
119122

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
448448
case Builtin::BI__builtin_cosf16:
449449
case Builtin::BI__builtin_cosl:
450450
case Builtin::BI__builtin_cosf128:
451-
assert(getContext().getLangOpts().FastMath &&
452-
"cir.cos is only expected under -ffast-math");
451+
assert(!MissingFeatures::fastMathFlags());
453452
return buildUnaryFPBuiltin<mlir::cir::CosOp>(*this, *E);
454453

455454
case Builtin::BIexp:
@@ -460,8 +459,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
460459
case Builtin::BI__builtin_expf16:
461460
case Builtin::BI__builtin_expl:
462461
case Builtin::BI__builtin_expf128:
463-
assert(getContext().getLangOpts().FastMath &&
464-
"cir.exp is only expected under -ffast-math");
462+
assert(!MissingFeatures::fastMathFlags());
465463
return buildUnaryFPBuiltin<mlir::cir::ExpOp>(*this, *E);
466464

467465
case Builtin::BIexp2:
@@ -472,8 +470,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
472470
case Builtin::BI__builtin_exp2f16:
473471
case Builtin::BI__builtin_exp2l:
474472
case Builtin::BI__builtin_exp2f128:
475-
assert(getContext().getLangOpts().FastMath &&
476-
"cir.exp2 is only expected under -ffast-math");
473+
assert(!MissingFeatures::fastMathFlags());
477474
return buildUnaryFPBuiltin<mlir::cir::Exp2Op>(*this, *E);
478475

479476
case Builtin::BIfabs:
@@ -540,8 +537,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
540537
case Builtin::BI__builtin_fmod:
541538
case Builtin::BI__builtin_fmodf:
542539
case Builtin::BI__builtin_fmodl:
543-
assert(getContext().getLangOpts().FastMath &&
544-
"cir.fmod is only expected under -ffast-math");
540+
assert(!MissingFeatures::fastMathFlags());
545541
return buildBinaryFPBuiltin<mlir::cir::FModOp>(*this, *E);
546542

547543
case Builtin::BI__builtin_fmodf16:
@@ -556,8 +552,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
556552
case Builtin::BI__builtin_logf16:
557553
case Builtin::BI__builtin_logl:
558554
case Builtin::BI__builtin_logf128:
559-
assert(getContext().getLangOpts().FastMath &&
560-
"cir.log is only expected under -ffast-math");
555+
assert(!MissingFeatures::fastMathFlags());
561556
return buildUnaryFPBuiltin<mlir::cir::LogOp>(*this, *E);
562557

563558
case Builtin::BIlog10:
@@ -568,8 +563,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
568563
case Builtin::BI__builtin_log10f16:
569564
case Builtin::BI__builtin_log10l:
570565
case Builtin::BI__builtin_log10f128:
571-
assert(getContext().getLangOpts().FastMath &&
572-
"cir.log10 is only expected under -ffast-math");
566+
assert(!MissingFeatures::fastMathFlags());
573567
return buildUnaryFPBuiltin<mlir::cir::Log10Op>(*this, *E);
574568

575569
case Builtin::BIlog2:
@@ -580,8 +574,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
580574
case Builtin::BI__builtin_log2f16:
581575
case Builtin::BI__builtin_log2l:
582576
case Builtin::BI__builtin_log2f128:
583-
assert(getContext().getLangOpts().FastMath &&
584-
"cir.log2 is only expected under -ffast-math");
577+
assert(!MissingFeatures::fastMathFlags());
585578
return buildUnaryFPBuiltin<mlir::cir::Log2Op>(*this, *E);
586579

587580
case Builtin::BInearbyint:
@@ -599,8 +592,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
599592
case Builtin::BI__builtin_pow:
600593
case Builtin::BI__builtin_powf:
601594
case Builtin::BI__builtin_powl:
602-
assert(getContext().getLangOpts().FastMath &&
603-
"cir.pow is only expected under -ffast-math");
595+
assert(!MissingFeatures::fastMathFlags());
604596
return RValue::get(
605597
buildBinaryMaybeConstrainedFPBuiltin<mlir::cir::PowOp>(*this, *E));
606598

@@ -636,8 +628,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
636628
case Builtin::BI__builtin_sinf16:
637629
case Builtin::BI__builtin_sinl:
638630
case Builtin::BI__builtin_sinf128:
639-
assert(getContext().getLangOpts().FastMath &&
640-
"cir.sin is only expected under -ffast-math");
631+
assert(!MissingFeatures::fastMathFlags());
641632
return buildUnaryFPBuiltin<mlir::cir::SinOp>(*this, *E);
642633

643634
case Builtin::BIsqrt:
@@ -648,8 +639,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
648639
case Builtin::BI__builtin_sqrtf16:
649640
case Builtin::BI__builtin_sqrtl:
650641
case Builtin::BI__builtin_sqrtf128:
651-
assert(getContext().getLangOpts().FastMath &&
652-
"cir.sqrt is only expected under -ffast-math");
642+
assert(!MissingFeatures::fastMathFlags());
653643
return buildUnaryFPBuiltin<mlir::cir::SqrtOp>(*this, *E);
654644

655645
case Builtin::BItrunc:

clang/test/CIR/CodeGen/builtin-floating-point.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -ffast-math -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t1.cir 2>&1 | FileCheck %s
2-
// RUN: %clang_cc1 -triple aarch64-apple-darwin-macho -ffast-math -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t1.cir 2>&1 | FileCheck %s --check-prefix=AARCH64
3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -ffast-math -fclangir -emit-llvm -o %t.ll %s
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t1.cir 2>&1 | FileCheck %s
2+
// RUN: %clang_cc1 -triple aarch64-apple-darwin-macho -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t1.cir 2>&1 | FileCheck %s --check-prefix=AARCH64
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o %t.ll %s
44
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM
55

66
// lround

0 commit comments

Comments
 (0)