3131#define LLVM_BUILD_OP_OR_INTRINSIC (Op , left , right , res , intrinsic , name , \
3232 err_ret ) \
3333 do { \
34- if (comp_ctx->disable_llvm_intrinsics && !is_i32 \
34+ if (comp_ctx->disable_llvm_intrinsics \
3535 && aot_intrinsic_check_capability(comp_ctx, intrinsic)) { \
3636 res = aot_call_llvm_intrinsic(comp_ctx, func_ctx, intrinsic, \
3737 param_types[0], param_types, 2, \
@@ -234,8 +234,6 @@ compile_op_float_min_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
234234 nan = LLVMConstRealOfString (ret_type , "NaN" );
235235 char * intrinsic = is_min ? (is_f32 ? "llvm.minnum.f32" : "llvm.minnum.f64" )
236236 : (is_f32 ? "llvm.maxnum.f32" : "llvm.maxnum.f64" );
237- bool is_i32 = is_f32 ;
238-
239237 CHECK_LLVM_CONST (nan );
240238
241239 param_types [0 ] = param_types [1 ] = ret_type ;
@@ -292,11 +290,13 @@ compile_op_float_min_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
292290 }
293291
294292 if (is_min )
295- LLVM_BUILD_OP_OR_INTRINSIC (Or , left_int , right_int , tmp , "i64.or" ,
296- "tmp_int" , false);
293+ LLVM_BUILD_OP_OR_INTRINSIC (Or , left_int , right_int , tmp ,
294+ is_f32 ? "i32.or" : "i64.or" , "tmp_int" ,
295+ false);
297296 else
298- LLVM_BUILD_OP_OR_INTRINSIC (And , left_int , right_int , tmp , "i64.and" ,
299- "tmp_int" , false);
297+ LLVM_BUILD_OP_OR_INTRINSIC (And , left_int , right_int , tmp ,
298+ is_f32 ? "i32.and" : "i64.and" , "tmp_int" ,
299+ false);
300300
301301 if (!(tmp = LLVMBuildBitCast (comp_ctx -> builder , tmp , ret_type , "tmp" ))) {
302302 aot_set_last_error ("llvm build bitcast fail." );
@@ -402,7 +402,8 @@ compile_rems(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
402402 LLVMPositionBuilderAtEnd (comp_ctx -> builder , no_overflow_block );
403403
404404 LLVM_BUILD_OP_OR_INTRINSIC (SRem , left , right , no_overflow_value ,
405- "i64.rem_s" , "rem_s" , false);
405+ is_i32 ? "i32.rem_s" : "i64.rem_s" , "rem_s" ,
406+ false);
406407
407408 /* Jump to rems_end block */
408409 if (!LLVMBuildBr (comp_ctx -> builder , rems_end_block )) {
@@ -516,20 +517,24 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
516517 /* Build div */
517518 switch (arith_op ) {
518519 case INT_DIV_S :
519- LLVM_BUILD_OP_OR_INTRINSIC (SDiv , left , right , res ,
520- "i64.div_s" , "div_s" , false);
520+ LLVM_BUILD_OP_OR_INTRINSIC (
521+ SDiv , left , right , res ,
522+ is_i32 ? "i32.div_s" : "i64.div_s" , "div_s" , false);
521523 break ;
522524 case INT_DIV_U :
523- LLVM_BUILD_OP_OR_INTRINSIC (UDiv , left , right , res ,
524- "i64.div_u" , "div_u" , false);
525+ LLVM_BUILD_OP_OR_INTRINSIC (
526+ UDiv , left , right , res ,
527+ is_i32 ? "i32.div_u" : "i64.div_u" , "div_u" , false);
525528 break ;
526529 case INT_REM_S :
527- LLVM_BUILD_OP_OR_INTRINSIC (SRem , left , right , res ,
528- "i64.rem_s" , "rem_s" , false);
530+ LLVM_BUILD_OP_OR_INTRINSIC (
531+ SRem , left , right , res ,
532+ is_i32 ? "i32.rem_s" : "i64.rem_s" , "rem_s" , false);
529533 break ;
530534 case INT_REM_U :
531- LLVM_BUILD_OP_OR_INTRINSIC (URem , left , right , res ,
532- "i64.rem_u" , "rem_u" , false);
535+ LLVM_BUILD_OP_OR_INTRINSIC (
536+ URem , left , right , res ,
537+ is_i32 ? "i32.rem_u" : "i64.rem_u" , "rem_u" , false);
533538 break ;
534539 default :
535540 bh_assert (0 );
@@ -568,7 +573,8 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
568573 check_overflow_succ )))
569574 goto fail ;
570575
571- LLVM_BUILD_OP_OR_INTRINSIC (SDiv , left , right , res , "i64.div_s" ,
576+ LLVM_BUILD_OP_OR_INTRINSIC (SDiv , left , right , res ,
577+ is_i32 ? "i32.div_s" : "i64.div_s" ,
572578 "div_s" , false);
573579 PUSH_INT (res );
574580 return true;
@@ -594,7 +600,8 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
594600 return compile_rems (comp_ctx , func_ctx , left , right , overflow ,
595601 is_i32 );
596602 case INT_REM_U :
597- LLVM_BUILD_OP_OR_INTRINSIC (URem , left , right , res , "i64.rem_u" ,
603+ LLVM_BUILD_OP_OR_INTRINSIC (URem , left , right , res ,
604+ is_i32 ? "i32.rem_u" : "i64.rem_u" ,
598605 "rem_u" , false);
599606 PUSH_INT (res );
600607 return true;
0 commit comments