From 177aa4fc7919695f154cbf4f267ec0680c4b020a Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 12 Jul 2022 13:43:56 +0800 Subject: [PATCH] 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. --- core/iwasm/compilation/aot_emit_numberic.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/iwasm/compilation/aot_emit_numberic.c b/core/iwasm/compilation/aot_emit_numberic.c index ed1784e1..44e65a0c 100644 --- a/core/iwasm/compilation/aot_emit_numberic.c +++ b/core/iwasm/compilation/aot_emit_numberic.c @@ -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);