Fix aot rotl/rotr 0 issue (#1285)

Fix the issue reported in #1282.
When i32/i64 rotate (rotl/rotr) with 0, the LLVM IRs translated are:
left<<0 | left>>64 and left >>0 | left<<64
The value of left >> 64 and left <<64 in LLVM are treated as poison,
which causes invalid result when executing the aot function.

Directly return left when right is 0 to fix the issue.
This commit is contained in:
Wenyong Huang 2022-07-12 13:43:56 +08:00 committed by GitHub
parent 0f6e5a55a4
commit 177aa4fc79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -692,6 +692,10 @@ compile_int_rot(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right,
SHIFT_COUNT_MASK;
/* rotl/rotr with 0 */
if (IS_CONST_ZERO(right))
return left;
/* Calculate (bits - shif_count) */
LLVM_BUILD_OP(Sub, is_i32 ? I32_32 : I64_64, right, bits_minus_shift_count,
"bits_minus_shift_count", NULL);