From 2dd459528c250525fe816045e0bb25a0e93e362e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:42:47 +0000 Subject: [PATCH 1/4] Initial plan From b21946520bec7bbb91fa6819fc24a96ab7dfbb08 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:53:22 +0000 Subject: [PATCH 2/4] Fix value profiling to record function pointer instead of index Co-authored-by: Lukasdoe <33507994+Lukasdoe@users.noreply.github.com> --- core/iwasm/compilation/aot_emit_function.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index e9f5fce07d..ce1e331133 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2770,12 +2770,12 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, I32_CONST(0)); /* counter index 0 */ /* Now add value profiling to capture the call target */ - /* Convert func_idx to i64 for value profiling */ - LLVMValueRef func_idx_i64 = LLVMBuildZExt(comp_ctx->builder, - func_idx, I64_TYPE, - "func_idx_i64"); - if (!func_idx_i64) { - aot_set_last_error("llvm build zext failed."); + /* Convert func_ptr to i64 for value profiling */ + LLVMValueRef func_ptr_i64 = LLVMBuildPtrToInt(comp_ctx->builder, + func_ptr, I64_TYPE, + "func_ptr_i64"); + if (!func_ptr_i64) { + aot_set_last_error("llvm build ptrtoint failed."); goto fail; } @@ -2790,7 +2790,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, "llvm.instrprof.value.profile", VOID_TYPE, value_prof_param_types, 5, glob, I64_CONST(func_ctx->aot_func->func_idx), - func_idx_i64, + func_ptr_i64, I32_CONST(0), /* IPVK_IndirectCallTarget */ I32_CONST(0)); /* call site index */ } From c928a65ca7e56f9859dbb1c0cdb7827b7dfd7a16 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:55:31 +0000 Subject: [PATCH 3/4] Add detailed comment explaining value profiling fix Co-authored-by: Lukasdoe <33507994+Lukasdoe@users.noreply.github.com> --- core/iwasm/compilation/aot_emit_function.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index ce1e331133..2ee778929a 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -2769,7 +2769,10 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, I32_CONST(1), /* 1 counter for this call site */ I32_CONST(0)); /* counter index 0 */ - /* Now add value profiling to capture the call target */ + /* Now add value profiling to capture the call target. + * LLVM's value profiling expects the actual function pointer address, + * not the WebAssembly function index. This allows LLVM to correlate + * the runtime target with the actual compiled function for PGO. */ /* Convert func_ptr to i64 for value profiling */ LLVMValueRef func_ptr_i64 = LLVMBuildPtrToInt(comp_ctx->builder, func_ptr, I64_TYPE, From d6c0011584a8fa366b49462d4a88a5cfd75435e8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:58:59 +0000 Subject: [PATCH 4/4] Complete fix for value profiling Co-authored-by: Lukasdoe <33507994+Lukasdoe@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000000..945c9b46d6 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file