From: WANG Rui Date: Fri, 19 Sep 2025 12:49:01 +0000 (+0800) Subject: tcg/optimize: Fix folding of vector bitsel X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a50347a4145faf6d409afd4b9b682c8b3e60854a;p=thirdparty%2Fqemu.git tcg/optimize: Fix folding of vector bitsel It looks like a typo. When the false value (C) is the constant -1, the correct fold should be: R = B | ~A Reproducer (LoongArch64 assembly): .text .globl _start _start: vldi $vr1, 3073 vldi $vr2, 1023 vbitsel.v $vr0, $vr2, $vr1, $vr2 vpickve2gr.d $a1, $vr0, 1 xori $a0, $a1, 1 li.w $a7, 93 syscall 0 Fixes: e58b977238e3 ("tcg/optimize: Optimize bitsel_vec") Link: https://github.com/llvm/llvm-project/issues/159610 Signed-off-by: WANG Rui Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20250919124901.2756538-1-wangrui@loongson.cn> --- diff --git a/tcg/optimize.c b/tcg/optimize.c index 3638ab9fea0..f69702b26e8 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -1568,9 +1568,10 @@ static bool fold_bitsel_vec(OptContext *ctx, TCGOp *op) return fold_and(ctx, op); } if (fv == -1 && TCG_TARGET_HAS_orc_vec) { + TCGArg ta = op->args[2]; op->opc = INDEX_op_orc_vec; op->args[2] = op->args[1]; - op->args[1] = op->args[3]; + op->args[1] = ta; return fold_orc(ctx, op); } }