@@ -653,15 +653,22 @@ compile_int_sub(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right,
653653}
654654
655655static LLVMValueRef
656- compile_int_mul (AOTCompContext * comp_ctx , LLVMValueRef left , LLVMValueRef right ,
657- bool is_i32 )
656+ compile_int_mul (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
657+ LLVMValueRef left , LLVMValueRef right , bool is_i32 )
658658{
659659 /* If one of the operands is 0, just return constant 0 */
660660 if (IS_CONST_ZERO (left ) || IS_CONST_ZERO (right ))
661661 return is_i32 ? I32_ZERO : I64_ZERO ;
662662
663663 /* Build mul */
664- return LLVMBuildMul (comp_ctx -> builder , left , right , "mul" );
664+ LLVMTypeRef param_types [2 ];
665+ param_types [1 ] = param_types [0 ] = is_i32 ? I32_TYPE : I64_TYPE ;
666+
667+ LLVMValueRef res ;
668+ LLVM_BUILD_OP_OR_INTRINSIC (Mul , left , right , res ,
669+ is_i32 ? "i32.mul" : "i64.mul" , "mul" , false);
670+
671+ return res ;
665672}
666673
667674static bool
@@ -679,8 +686,9 @@ compile_op_int_arithmetic(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
679686 "compile int sub fail." );
680687 return true;
681688 case INT_MUL :
682- DEF_INT_BINARY_OP (compile_int_mul (comp_ctx , left , right , is_i32 ),
683- "compile int mul fail." );
689+ DEF_INT_BINARY_OP (
690+ compile_int_mul (comp_ctx , func_ctx , left , right , is_i32 ),
691+ "compile int mul fail." );
684692 return true;
685693 case INT_DIV_S :
686694 case INT_DIV_U :
@@ -726,43 +734,57 @@ compile_op_int_bitwise(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
726734}
727735
728736static LLVMValueRef
729- compile_int_shl (AOTCompContext * comp_ctx , LLVMValueRef left , LLVMValueRef right ,
730- bool is_i32 )
737+ compile_int_shl (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
738+ LLVMValueRef left , LLVMValueRef right , bool is_i32 )
731739{
732740 LLVMValueRef res ;
733741
734742 SHIFT_COUNT_MASK ;
735743
736744 /* Build shl */
737- LLVM_BUILD_OP (Shl , left , right , res , "shl" , NULL );
745+ LLVMTypeRef param_types [2 ];
746+ param_types [1 ] = param_types [0 ] = is_i32 ? I32_TYPE : I64_TYPE ;
747+
748+ LLVM_BUILD_OP_OR_INTRINSIC (Shl , left , right , res ,
749+ is_i32 ? "i32.shl" : "i64.shl" , "shl" , false);
738750
739751 return res ;
740752}
741753
742754static LLVMValueRef
743- compile_int_shr_s (AOTCompContext * comp_ctx , LLVMValueRef left ,
744- LLVMValueRef right , bool is_i32 )
755+ compile_int_shr_s (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
756+ LLVMValueRef left , LLVMValueRef right , bool is_i32 )
745757{
746758 LLVMValueRef res ;
747759
748760 SHIFT_COUNT_MASK ;
749761
750762 /* Build shl */
751- LLVM_BUILD_OP (AShr , left , right , res , "shr_s" , NULL );
763+ LLVMTypeRef param_types [2 ];
764+ param_types [1 ] = param_types [0 ] = is_i32 ? I32_TYPE : I64_TYPE ;
765+
766+ LLVM_BUILD_OP_OR_INTRINSIC (AShr , left , right , res ,
767+ is_i32 ? "i32.shr_s" : "i64.shr_s" , "shr_s" ,
768+ false);
752769
753770 return res ;
754771}
755772
756773static LLVMValueRef
757- compile_int_shr_u (AOTCompContext * comp_ctx , LLVMValueRef left ,
758- LLVMValueRef right , bool is_i32 )
774+ compile_int_shr_u (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
775+ LLVMValueRef left , LLVMValueRef right , bool is_i32 )
759776{
760777 LLVMValueRef res ;
761778
762779 SHIFT_COUNT_MASK ;
763780
764781 /* Build shl */
765- LLVM_BUILD_OP (LShr , left , right , res , "shr_u" , NULL );
782+ LLVMTypeRef param_types [2 ];
783+ param_types [1 ] = param_types [0 ] = is_i32 ? I32_TYPE : I64_TYPE ;
784+
785+ LLVM_BUILD_OP_OR_INTRINSIC (LShr , left , right , res ,
786+ is_i32 ? "i32.shr_u" : "i64.shr_u" , "shr_u" ,
787+ false);
766788
767789 return res ;
768790}
@@ -814,16 +836,18 @@ compile_op_int_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
814836{
815837 switch (shift_op ) {
816838 case INT_SHL :
817- DEF_INT_BINARY_OP (compile_int_shl ( comp_ctx , left , right , is_i32 ),
818- NULL );
839+ DEF_INT_BINARY_OP (
840+ compile_int_shl ( comp_ctx , func_ctx , left , right , is_i32 ), NULL );
819841 return true;
820842 case INT_SHR_S :
821- DEF_INT_BINARY_OP (compile_int_shr_s (comp_ctx , left , right , is_i32 ),
822- NULL );
843+ DEF_INT_BINARY_OP (
844+ compile_int_shr_s (comp_ctx , func_ctx , left , right , is_i32 ),
845+ NULL );
823846 return true;
824847 case INT_SHR_U :
825- DEF_INT_BINARY_OP (compile_int_shr_u (comp_ctx , left , right , is_i32 ),
826- NULL );
848+ DEF_INT_BINARY_OP (
849+ compile_int_shr_u (comp_ctx , func_ctx , left , right , is_i32 ),
850+ NULL );
827851 return true;
828852 case INT_ROTL :
829853 DEF_INT_BINARY_OP (
0 commit comments