From d20d5c1034956e2af5bcef8f66706f9463e27e8a Mon Sep 17 00:00:00 2001 From: tyfkda Date: Sun, 12 Nov 2023 10:44:18 +0900 Subject: [PATCH] Prevent overwritten const value --- src/cc/arch/aarch64/ir_aarch64.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/arch/aarch64/ir_aarch64.c b/src/cc/arch/aarch64/ir_aarch64.c index 680e0c4dc..c398e835a 100644 --- a/src/cc/arch/aarch64/ir_aarch64.c +++ b/src/cc/arch/aarch64/ir_aarch64.c @@ -929,7 +929,9 @@ void tweak_irs(FuncBackend *fnbe) { if (ir->opr2->flag & VRF_CONST) { if (ir->opr2->fixnum < 0) { ir->kind = IR_SUB; - ir->opr2->fixnum = -ir->opr2->fixnum; + VReg *old = ir->opr2; + ir->opr2 = reg_alloc_spawn_const(fnbe->ra, -old->fixnum, old->vsize); + ir->opr2->flag = old->flag; } if (ir->opr2->fixnum > 0x0fff) insert_const_mov(&ir->opr2, ra, irs, j++); @@ -949,7 +951,9 @@ void tweak_irs(FuncBackend *fnbe) { if (ir->opr2->flag & VRF_CONST) { if (ir->opr2->fixnum < 0) { ir->kind = IR_ADD; - ir->opr2->fixnum = -ir->opr2->fixnum; + VReg *old = ir->opr2; + ir->opr2 = reg_alloc_spawn_const(fnbe->ra, -old->fixnum, old->vsize); + ir->opr2->flag = old->flag; } if (ir->opr2->fixnum > 0x0fff) insert_const_mov(&ir->opr2, ra, irs, j++);