From ab5490415bb28ef6cdd8045d116a9951aa171c8e Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Tue, 20 Aug 2024 20:57:51 -0700 Subject: [PATCH] add inline attr to remove one indirection --- compiler/rustc_codegen_llvm/src/back/write.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index d6787d02ea154..b3d24b26b564b 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -1069,6 +1069,12 @@ pub(crate) unsafe fn enzyme_ad( _ => unreachable!(), }; let mut res: &Value = tmp.0; + // res is getting wrapped, but we don't want the perf overhead of a fnc call indirection. + // So we'll add an alwaysinline attribute to let llvm handle it for us. + let always_inline = llvm::AttributeKind::AlwaysInline; + let attr = llvm::LLVMRustCreateAttrNoValue(llcx, always_inline); + llvm::LLVMRustAddFunctionAttributes(res, 9, &attr, 1); + let size_positions: Vec = tmp.1; let f_return_type = LLVMGetReturnType(LLVMGlobalGetValueType(res));