aot compiler: Fix NaN handling for opcode f32/f64.const in XIP mode (#3721)

If the value of a float constant is an NaN, the aot compiler creates an alloca,
stores the converted i32 const into it and then loads f32 from it again, which
may introduce a relocation in the AOT file and is not allowed for XIP mode.
This commit is contained in:
Huang Qi
2024-08-16 14:04:41 +08:00
committed by GitHub
parent 59f761b58d
commit 4c127715df

View File

@ -68,23 +68,21 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
{ {
LLVMValueRef alloca, value; LLVMValueRef alloca, value;
if (!isnan(f32_const)) { if (comp_ctx->is_indirect_mode
if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f32.const")) {
&& aot_intrinsic_check_capability(comp_ctx, "f32.const")) { WASMValue wasm_value;
WASMValue wasm_value; memcpy(&wasm_value.f32, &f32_const, sizeof(float32));
memcpy(&wasm_value.f32, &f32_const, sizeof(float32)); value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol,
value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F32);
&wasm_value, VALUE_TYPE_F32); if (!value) {
if (!value) { return false;
return false;
}
PUSH_F32(value);
}
else {
value = F32_CONST(f32_const);
CHECK_LLVM_CONST(value);
PUSH_F32(value);
} }
PUSH_F32(value);
}
else if (!isnan(f32_const)) {
value = F32_CONST(f32_const);
CHECK_LLVM_CONST(value);
PUSH_F32(value);
} }
else { else {
int32 i32_const; int32 i32_const;
@ -123,23 +121,21 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
{ {
LLVMValueRef alloca, value; LLVMValueRef alloca, value;
if (!isnan(f64_const)) { if (comp_ctx->is_indirect_mode
if (comp_ctx->is_indirect_mode && aot_intrinsic_check_capability(comp_ctx, "f64.const")) {
&& aot_intrinsic_check_capability(comp_ctx, "f64.const")) { WASMValue wasm_value;
WASMValue wasm_value; memcpy(&wasm_value.f64, &f64_const, sizeof(float64));
memcpy(&wasm_value.f64, &f64_const, sizeof(float64)); value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol,
value = aot_load_const_from_table(comp_ctx, func_ctx->native_symbol, &wasm_value, VALUE_TYPE_F64);
&wasm_value, VALUE_TYPE_F64); if (!value) {
if (!value) { return false;
return false;
}
PUSH_F64(value);
}
else {
value = F64_CONST(f64_const);
CHECK_LLVM_CONST(value);
PUSH_F64(value);
} }
PUSH_F64(value);
}
else if (!isnan(f64_const)) {
value = F64_CONST(f64_const);
CHECK_LLVM_CONST(value);
PUSH_F64(value);
} }
else { else {
int64 i64_const; int64 i64_const;