https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/246016
>From 7afce64206837ac1a178efbebc9f277783fddbbd Mon Sep 17 00:00:00 2001 From: Henrich Lauko <[email protected]> Date: Thu, 26 Nov 2026 06:20:21 +0000 Subject: [PATCH] [CIR] Mark calls in strictfp functions strictfp LangRef requires every call in a function that uses constrained FP intrinsics to be `strictfp`, at the call site or on the callee, and LLVM checks the call, not its caller, before it folds or simplifies a libcall. Classic codegen gets the attribute from IRBuilder's constrained mode. ClangIR marked only the function, so at -O1 LLVM folded `erf(1.0)` to a constant under `FENV_ACCESS ON`. The lowering now maps the CIR `strictfp` function attribute to the `strictfp` attribute of `llvm.func` instead of a `passthrough` entry. After the conversion to the LLVM dialect, it sets `strictfp` on every `llvm.call`, `llvm.invoke`, `llvm.inline_asm` and `llvm.call_intrinsic` in a `strictfp` function. That covers direct and indirect calls, invokes, inline assembly, constrained intrinsics, and the calls that LoweringPrepare and EH lowering create. CIR does not change, `strictfp` stays a function attribute. The marks are part of the LLVM dialect, so they survive any route to LLVM IR. Calls from named intrinsic ops such as `llvm.intr.fabs` and `llvm.intr.memcpy` stay unmarked, because the LLVM dialect has no call-site attributes on those ops. Classic codegen marks them. ClangIR also marks call and construct expressions in a strictfp global initializer, as LangRef asks. Classic codegen leaves those unmarked, because it adds `strictfp` back to such a call only if the enclosing declaration is a strictfp function. The `_GLOBAL__sub_I_*` function is not `strictfp` in ClangIR yet, so its calls stay unmarked. Assisted-by: Claude Code (Opus 5.5). --- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 24 +++- clang/test/CIR/CodeGen/strictfp-call-site.c | 118 ++++++++++++++++++ clang/test/CIR/CodeGen/strictfp-call-site.cpp | 86 +++++++++++++ .../no-trapping-math-ssp-buffer-size.cir | 3 +- .../CIR/Lowering/strictfp-call-site-asm.cir | 32 +++++ .../test/CIR/Lowering/strictfp-call-site.cir | 115 +++++++++++++++++ clang/test/CIR/Lowering/strictfp.cir | 7 +- 7 files changed, 379 insertions(+), 6 deletions(-) create mode 100644 clang/test/CIR/CodeGen/strictfp-call-site.c create mode 100644 clang/test/CIR/CodeGen/strictfp-call-site.cpp create mode 100644 clang/test/CIR/Lowering/strictfp-call-site-asm.cir create mode 100644 clang/test/CIR/Lowering/strictfp-call-site.cir diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 245ce5096d461a..ce725f40c4060a 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -3319,6 +3319,9 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite( if (op->hasAttr(CIRDialect::getOptNoneAttrName())) fn.setOptimizeNone(true); + if (op->hasAttr(CIRDialect::getStrictFPAttrName())) + fn.setStrictfp(true); + if (std::optional<cir::UnwindTableKind> uwtableKind = op.getUwtable()) fn.setUwtableKindAttr(mlir::LLVM::UWTableKindAttr::get( fn.getContext(), convertUWTableKind(*uwtableKind))); @@ -3334,7 +3337,7 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite( // attributes. SmallVector<mlir::Attribute> passthrough; for (llvm::StringRef flagAttr : - {CIRDialect::getStrictFPAttrName(), CIRDialect::getNoRecurseAttrName(), + {CIRDialect::getNoRecurseAttrName(), CIRDialect::getMustProgressAttrName(), CIRDialect::getNoBuiltinAttrName(), CIRDialect::getNakedAttrName()}) if (op->hasAttr(flagAttr)) @@ -5259,6 +5262,23 @@ struct GPULaunchFuncOperandLowering : public mlir::ConversionPattern { }; } // namespace +/// Marks every call in a `strictfp` function `strictfp`, which LangRef +/// requires in a function that uses constrained FP intrinsics. Named intrinsic +/// ops such as `llvm.intr.memcpy` have no call-site attributes in the LLVM +/// dialect, so their calls stay unmarked. +static void markCallsInStrictFPFunctions(mlir::ModuleOp module) { + module.walk([](mlir::LLVM::LLVMFuncOp fn) { + if (!fn.getStrictfp()) + return; + fn.walk([](mlir::Operation *op) { + llvm::TypeSwitch<mlir::Operation *>(op) + .Case<mlir::LLVM::CallOp, mlir::LLVM::InvokeOp, + mlir::LLVM::InlineAsmOp, mlir::LLVM::CallIntrinsicOp>( + [](auto call) { call.setStrictfp(true); }); + }); + }); +} + void ConvertCIRToLLVMPass::runOnOperation() { llvm::TimeTraceScope scope("Convert CIR to LLVM Pass"); @@ -5361,6 +5381,8 @@ void ConvertCIRToLLVMPass::runOnOperation() { return; } + markCallsInStrictFPFunctions(module); + // Drop CIR-native data-layout entries. if (auto dlSpec = mlir::dyn_cast_or_null<mlir::DataLayoutSpecAttr>( module->getAttr(mlir::DLTIDialect::kDataLayoutAttrName))) { diff --git a/clang/test/CIR/CodeGen/strictfp-call-site.c b/clang/test/CIR/CodeGen/strictfp-call-site.c new file mode 100644 index 00000000000000..36de5edb665ce5 --- /dev/null +++ b/clang/test/CIR/CodeGen/strictfp-call-site.c @@ -0,0 +1,118 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefixes=LLVM,LLVMCIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefixes=LLVM,OGCG + +// LLVM requires every call in a function that uses constrained FP intrinsics +// to be strictfp, at the call site or on the callee. CIR keeps strictfp on the +// function only. The lowering to the LLVM dialect marks the calls in it, +// including the libcalls that LoweringPrepare creates. + +void ext(void); +float extf(float); +struct S { int a[32]; }; + +void plain_direct(void) { ext(); } + +// CIR: cir.func {{.*}}@plain_direct() +// CIR: cir.call @ext() : () -> () + +// LLVM: define {{.*}}void @plain_direct() #[[PLAIN_FN:[0-9]+]] +// LLVM: call void @ext(){{$}} + +void plain_indirect(void (*fp)(void)) { fp(); } + +// LLVM: define {{.*}}void @plain_indirect(ptr {{.*}}) #[[PLAIN_FN]] +// LLVM: call void %{{.*}}(){{$}} + +void plain_copy(struct S *d, struct S *s) { *d = *s; } + +// LLVM: define {{.*}}void @plain_copy(ptr {{.*}}, ptr {{.*}}) #[[PLAIN_FN]] +// LLVM: call void @llvm.memcpy.p0.p0.i64({{.*}}, i64 128, i1 false){{$}} + +// Classic codegen marks inline assembly nounwind. +void plain_asm(void) { __asm__ volatile("nop"); } + +// LLVM: define {{.*}}void @plain_asm() #[[PLAIN_FN]] +// LLVMCIR: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"(){{$}} +// OGCG: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() #[[NOUNWIND_CALL:[0-9]+]] + +#pragma STDC FENV_ACCESS ON + +void strict_direct(void) { ext(); } + +// The attribute stays on the function in CIR. +// CIR: cir.func {{.*}}@strict_direct() attributes {{{.*}}strictfp} +// CIR: cir.call @ext() : () -> () + +// LLVM: define {{.*}}void @strict_direct() #[[STRICT_FN:[0-9]+]] +// LLVM: call void @ext() #[[STRICT_CALL:[0-9]+]] + +void strict_indirect(void (*fp)(void)) { fp(); } + +// CIR: cir.func {{.*}}@strict_indirect({{.*}}) attributes {{{.*}}strictfp} +// CIR: cir.call %{{.*}}() : (!cir.ptr<!cir.func<()>>) -> () + +// LLVM: define {{.*}}void @strict_indirect(ptr {{.*}}) #[[STRICT_FN]] +// LLVM: call void %{{.*}}() #[[STRICT_CALL]] + +// A call next to a constrained operation. +float strict_mixed(float a) { return extf(a + 1.0f); } + +// LLVM: define {{.*}}float @strict_mixed(float {{.*}}) #[[STRICT_FN]] +// LLVM: call float @llvm.experimental.constrained.fadd.f32({{.*}}) #[[STRICT_CALL]] +// LLVM: call float @extf(float {{.*}}) #[[STRICT_CALL]] + +// An intrinsic that has no constrained variant. The LLVM dialect's named +// intrinsic ops have no call-site attributes, so ClangIR leaves it unmarked. +float strict_builtin(float a) { return __builtin_fabsf(a); } + +// LLVM: define {{.*}}float @strict_builtin(float {{.*}}) #[[STRICT_FN]] +// LLVMCIR: call float @llvm.fabs.f32(float %{{.*}}){{$}} +// OGCG: call float @llvm.fabs.f32(float %{{.*}}) #[[STRICT_CALL]] + +// An intrinsic that the lowering creates for an operation that is not a call. +// It is a named intrinsic op too. +void strict_copy(struct S *d, struct S *s) { *d = *s; } + +// CIR: cir.func {{.*}}@strict_copy({{.*}}) attributes {{{.*}}strictfp} +// CIR: cir.copy + +// LLVM: define {{.*}}void @strict_copy(ptr {{.*}}, ptr {{.*}}) #[[STRICT_FN]] +// LLVMCIR: call void @llvm.memcpy.p0.p0.i64({{.*}}, i64 128, i1 false){{$}} +// OGCG: call void @llvm.memcpy.p0.p0.i64({{.*}}, i64 128, i1 false) #[[STRICT_CALL]] + +// A libcall that LoweringPrepare creates. Classic codegen also marks it +// nounwind. +_Complex float strict_complex_mul(_Complex float a, _Complex float b) { + return a * b; +} + +// LLVM: define {{.*}}<2 x float> @strict_complex_mul( +// LLVMCIR: call <2 x float> @__mulsc3({{.*}}) #[[STRICT_CALL]] +// OGCG: call <2 x float> @__mulsc3({{.*}}) #[[STRICT_NOUNWIND_CALL:[0-9]+]] + +// Inline assembly. Classic codegen also marks it nounwind. +void strict_asm(void) { __asm__ volatile("nop"); } + +// CIR: cir.func {{.*}}@strict_asm() attributes {{{.*}}strictfp} +// CIR: cir.asm(x86_att, + +// LLVM: define {{.*}}void @strict_asm() #[[STRICT_FN]] +// LLVMCIR: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() #[[STRICT_CALL]] +// OGCG: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() #[[STRICT_NOUNWIND_CALL]] + +#pragma STDC FENV_ACCESS OFF + +// A call to a strictfp function from a function that is not strictfp. +void plain_calls_strict(void) { strict_direct(); } + +// LLVM: define {{.*}}void @plain_calls_strict() #[[PLAIN_FN]] +// LLVM: call void @strict_direct(){{$}} + +// LLVM-DAG: attributes #[[STRICT_FN]] = { {{.*}}strictfp +// LLVM-DAG: attributes #[[STRICT_CALL]] = { strictfp } +// OGCG-DAG: attributes #[[NOUNWIND_CALL]] = { nounwind } +// OGCG-DAG: attributes #[[STRICT_NOUNWIND_CALL]] = { nounwind strictfp } diff --git a/clang/test/CIR/CodeGen/strictfp-call-site.cpp b/clang/test/CIR/CodeGen/strictfp-call-site.cpp new file mode 100644 index 00000000000000..1e93379194cd5f --- /dev/null +++ b/clang/test/CIR/CodeGen/strictfp-call-site.cpp @@ -0,0 +1,86 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions \ +// RUN: -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefixes=LLVM,LLVMCIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions \ +// RUN: -emit-llvm %s -o %t.ll +// RUN: FileCheck --input-file=%t.ll %s -check-prefixes=LLVM,OGCG + +// With a strict TU-wide default the global initializer is strictfp too. +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions \ +// RUN: -ffp-exception-behavior=strict -fclangir -emit-llvm %s -o %t-strict-cir.ll +// RUN: FileCheck --input-file=%t-strict-cir.ll %s \ +// RUN: -check-prefixes=LLVM-STRICT,LLVMCIR-STRICT +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions \ +// RUN: -ffp-exception-behavior=strict -emit-llvm %s -o %t-strict.ll +// RUN: FileCheck --input-file=%t-strict.ll %s \ +// RUN: -check-prefixes=LLVM-STRICT,OGCG-STRICT + +// Calls in a strictfp function are strictfp in LLVM IR, including invokes and +// the calls that EH lowering creates. + +float ext(); +struct C { C(); }; +struct D { ~D(); }; + +float g = ext() + 1.0f; + +// LLVM: define internal void @__cxx_global_var_init() +// LLVM: call noundef float @_Z3extv(){{$}} + +// Classic codegen marks a call it emits for a call expression only when the +// enclosing declaration is a strictfp function, so it leaves this one unmarked +// beside a constrained intrinsic. +// LLVM-STRICT: define internal void @__cxx_global_var_init() #[[INIT_FN:[0-9]+]] +// LLVMCIR-STRICT: call noundef float @_Z3extv() #[[STRICT_CALL:[0-9]+]] +// LLVMCIR-STRICT: call float @llvm.experimental.constrained.fadd.f32({{.*}}) #[[STRICT_CALL]] +// OGCG-STRICT: call noundef float @_Z3extv(){{$}} +// OGCG-STRICT: call float @llvm.experimental.constrained.fadd.f32({{.*}}) #[[STRICT_CALL:[0-9]+]] + +C c; + +// LLVM: define internal void @__cxx_global_var_init.1() +// LLVM: call void @_ZN1CC1Ev(ptr {{.*}}@c){{$}} + +// The same holds for a construct expression. +// LLVM-STRICT: define internal void @__cxx_global_var_init.1() #[[INIT_FN]] +// LLVMCIR-STRICT: call void @_ZN1CC1Ev(ptr {{.*}}@c) #[[STRICT_CALL]] +// OGCG-STRICT: call void @_ZN1CC1Ev(ptr {{.*}}@c){{$}} + +float plain() { + D d; + return ext(); +} + +// LLVM: define {{.*}}float @_Z5plainv() +// LLVM: invoke noundef float @_Z3extv(){{$}} +// LLVM: call void @_ZN1DD1Ev(ptr {{.*}}) #[[NOUNWIND_CALL:[0-9]+]] + +float strict() { +#pragma STDC FENV_ACCESS ON + D d; + try { + return ext(); + } catch (...) { + return 0; + } +} + +// Classic codegen marks __cxa_begin_catch nounwind and invokes +// __cxa_end_catch. +// LLVM: define {{.*}}float @_Z6strictv() #[[STRICT_FN:[0-9]+]] +// LLVM: invoke noundef float @_Z3extv() #[[STRICT_CALL:[0-9]+]] +// LLVMCIR: call ptr @__cxa_begin_catch(ptr %{{.*}}) #[[STRICT_CALL]] +// OGCG: call ptr @__cxa_begin_catch(ptr %{{.*}}) #[[STRICT_NOUNWIND_CALL:[0-9]+]] +// LLVM: call float @llvm.experimental.constrained.sitofp.f32.i32({{.*}}) #[[STRICT_CALL]] +// LLVMCIR: call void @__cxa_end_catch() #[[STRICT_CALL]] +// OGCG: invoke void @__cxa_end_catch() #[[STRICT_CALL]] +// LLVMCIR: call void @_ZN1DD1Ev(ptr {{.*}}) #[[STRICT_NOUNWIND_CALL:[0-9]+]] +// OGCG: call void @_ZN1DD1Ev(ptr {{.*}}) #[[STRICT_NOUNWIND_CALL]] + +// LLVM-DAG: attributes #[[STRICT_FN]] = { {{.*}}strictfp +// LLVM-DAG: attributes #[[NOUNWIND_CALL]] = { nounwind } +// LLVM-DAG: attributes #[[STRICT_CALL]] = { strictfp } +// LLVM-DAG: attributes #[[STRICT_NOUNWIND_CALL]] = { nounwind strictfp } + +// LLVM-STRICT-DAG: attributes #[[INIT_FN]] = { {{.*}}strictfp +// LLVM-STRICT-DAG: attributes #[[STRICT_CALL]] = { strictfp } diff --git a/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir b/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir index d3508238c6b136..aeb12ebd3fe387 100644 --- a/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir +++ b/clang/test/CIR/Lowering/no-trapping-math-ssp-buffer-size.cir @@ -32,7 +32,8 @@ module attributes { // MLIR-LABEL: llvm.func @decl_fn() // MLIR-SAME: passthrough = {{\[}}["no-trapping-math", "true"], ["stack-protector-buffer-size", "16"]] // MLIR-LABEL: llvm.func @strictfp_fn() -// MLIR-SAME: passthrough = {{\[}}"strictfp", ["stack-protector-buffer-size", "16"]] +// MLIR-SAME: passthrough = {{\[}}["stack-protector-buffer-size", "16"]] +// MLIR-SAME: strictfp // MLIR-LABEL: llvm.func @runtime_fn() // MLIR-NOT: passthrough diff --git a/clang/test/CIR/Lowering/strictfp-call-site-asm.cir b/clang/test/CIR/Lowering/strictfp-call-site-asm.cir new file mode 100644 index 00000000000000..10d01984e466d7 --- /dev/null +++ b/clang/test/CIR/Lowering/strictfp-call-site-asm.cir @@ -0,0 +1,32 @@ +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// REQUIRES: target={{x86_64-.*-linux.*}} + +// Inline assembly in a `strictfp` function is a `strictfp` call. + +module attributes {cir.triple = "x86_64-unknown-linux-gnu"} { + cir.func @strict_asm() attributes {strictfp} { + cir.asm(x86_att, + out = [], + in = [], + in_out = [], + {"nop" "~{dirflag},~{fpsr},~{flags}"}) side_effects + cir.return + } + + // CHECK-LABEL: define void @strict_asm( + // CHECK: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() #[[STRICT:[0-9]+]] + + cir.func @plain_asm() { + cir.asm(x86_att, + out = [], + in = [], + in_out = [], + {"nop" "~{dirflag},~{fpsr},~{flags}"}) side_effects + cir.return + } + + // CHECK-LABEL: define void @plain_asm( + // CHECK: call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"(){{$}} +} + +// CHECK: attributes #[[STRICT]] = { strictfp } diff --git a/clang/test/CIR/Lowering/strictfp-call-site.cir b/clang/test/CIR/Lowering/strictfp-call-site.cir new file mode 100644 index 00000000000000..034d37cab6b529 --- /dev/null +++ b/clang/test/CIR/Lowering/strictfp-call-site.cir @@ -0,0 +1,115 @@ +// RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// REQUIRES: target={{x86_64-.*-linux.*}} + +// LLVM requires every call in a function that uses constrained FP intrinsics +// to be `strictfp`, at the call site or on the callee. CIR keeps `strictfp` on +// the function only, and the lowering sets `strictfp` on the LLVM dialect's +// direct and indirect calls, invokes and intrinsic calls. + +!s32i = !cir.int<s, 32> + +module attributes {cir.triple = "x86_64-unknown-linux-gnu"} { + cir.func private @__gxx_personality_v0(...) -> !s32i + cir.func private @callee(!s32i) -> !s32i + + cir.func @strict_direct(%arg0: !s32i) -> !s32i attributes {strictfp} { + %0 = cir.call @callee(%arg0) : (!s32i) -> !s32i + cir.return %0 : !s32i + } + + // MLIR-LABEL: llvm.func @strict_direct( + // MLIR: llvm.call @callee(%{{.*}}) {strictfp} : (i32) -> i32 + + // LLVM-LABEL: define i32 @strict_direct( + // LLVM: call i32 @callee(i32 %{{.*}}) #[[STRICT:[0-9]+]] + + cir.func @strict_nothrow(%arg0: !s32i) -> !s32i attributes {strictfp} { + %0 = cir.call @callee(%arg0) nothrow : (!s32i) -> !s32i + cir.return %0 : !s32i + } + + // MLIR-LABEL: llvm.func @strict_nothrow( + // MLIR: llvm.call @callee(%{{.*}}) {no_unwind, strictfp} : (i32) -> i32 + + // LLVM-LABEL: define i32 @strict_nothrow( + // LLVM: call i32 @callee(i32 %{{.*}}) #[[STRICT_NOUNWIND:[0-9]+]] + + cir.func @strict_indirect(%fn: !cir.ptr<!cir.func<(!s32i) -> !s32i>>, %arg0: !s32i) -> !s32i attributes {strictfp} { + %0 = cir.call %fn(%arg0) : (!cir.ptr<!cir.func<(!s32i) -> !s32i>>, !s32i) -> !s32i + cir.return %0 : !s32i + } + + // MLIR-LABEL: llvm.func @strict_indirect( + // MLIR: llvm.call %{{.*}}(%{{.*}}) {strictfp} : !llvm.ptr, (i32) -> i32 + + // LLVM-LABEL: define i32 @strict_indirect( + // LLVM: call i32 %{{.*}}(i32 %{{.*}}) #[[STRICT]] + + cir.func @strict_try_call(%arg0: !s32i) personality(@__gxx_personality_v0) attributes {strictfp} { + %0 = cir.try_call @callee(%arg0) ^normal, ^unwind : (!s32i) -> !s32i + ^normal: + cir.return + ^unwind: + %exception_ptr, %type_id = cir.eh.inflight_exception cleanup + cir.return + } + + // MLIR-LABEL: llvm.func @strict_try_call( + // MLIR: llvm.invoke @callee(%{{.*}}) to ^{{.*}} unwind ^{{.*}} {strictfp} : (i32) -> i32 + + // LLVM-LABEL: define void @strict_try_call( + // LLVM: invoke i32 @callee(i32 %{{.*}}) #[[STRICT]] + // LLVM-NEXT: to label %{{.*}} unwind label %{{.*}} + + cir.func @strict_intrinsic() attributes {strictfp} { + cir.call_llvm_intrinsic "donothing" : () -> () + cir.return + } + + // MLIR-LABEL: llvm.func @strict_intrinsic( + // MLIR: llvm.call_intrinsic "llvm.donothing"() {strictfp} : () -> () + + // LLVM-LABEL: define void @strict_intrinsic( + // LLVM: call void @llvm.donothing() #[[STRICT]] + + cir.func @plain_direct(%arg0: !s32i) -> !s32i { + %0 = cir.call @callee(%arg0) : (!s32i) -> !s32i + cir.return %0 : !s32i + } + + // MLIR-LABEL: llvm.func @plain_direct( + // MLIR: llvm.call @callee(%{{.*}}) : (i32) -> i32 + + // LLVM-LABEL: define i32 @plain_direct( + // LLVM: call i32 @callee(i32 %{{.*}}){{$}} + + cir.func @plain_indirect(%fn: !cir.ptr<!cir.func<(!s32i) -> !s32i>>, %arg0: !s32i) -> !s32i { + %0 = cir.call %fn(%arg0) : (!cir.ptr<!cir.func<(!s32i) -> !s32i>>, !s32i) -> !s32i + cir.return %0 : !s32i + } + + // MLIR-LABEL: llvm.func @plain_indirect( + // MLIR: llvm.call %{{.*}}(%{{.*}}) : !llvm.ptr, (i32) -> i32 + + // LLVM-LABEL: define i32 @plain_indirect( + // LLVM: call i32 %{{.*}}(i32 %{{.*}}){{$}} + + cir.func @plain_try_call(%arg0: !s32i) personality(@__gxx_personality_v0) { + %0 = cir.try_call @callee(%arg0) ^normal, ^unwind : (!s32i) -> !s32i + ^normal: + cir.return + ^unwind: + %exception_ptr, %type_id = cir.eh.inflight_exception cleanup + cir.return + } + + // MLIR-LABEL: llvm.func @plain_try_call( + // MLIR: llvm.invoke @callee(%{{.*}}) to ^{{.*}} unwind ^{{.*}} : (i32) -> i32 + + // LLVM-LABEL: define void @plain_try_call( + // LLVM: invoke i32 @callee(i32 %{{.*}}){{$}} +} + +// LLVM-DAG: attributes #[[STRICT]] = { strictfp } +// LLVM-DAG: attributes #[[STRICT_NOUNWIND]] = { nounwind strictfp } diff --git a/clang/test/CIR/Lowering/strictfp.cir b/clang/test/CIR/Lowering/strictfp.cir index 7c4abf807776bb..c4ed72e8f8b89f 100644 --- a/clang/test/CIR/Lowering/strictfp.cir +++ b/clang/test/CIR/Lowering/strictfp.cir @@ -3,9 +3,8 @@ // REQUIRES: target={{x86_64-.*-linux.*}} // Functions tagged with the `strictfp` CIR function attribute should be -// lowered to `llvm.func` operations whose `passthrough` array contains -// `"strictfp"`, and then translated to LLVM IR functions carrying the -// `strictfp` attribute. +// lowered to `llvm.func` operations with the `strictfp` attribute, and then +// translated to LLVM IR functions carrying the `strictfp` attribute. module { cir.func @strict_fn() attributes {strictfp} { @@ -18,7 +17,7 @@ module { } // MLIR-LABEL: llvm.func @strict_fn() -// MLIR-SAME: passthrough = ["strictfp"] +// MLIR-SAME: strictfp // MLIR-LABEL: llvm.func @plain_fn() // MLIR-NOT: passthrough // MLIR-NOT: strictfp _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
