Skip to content

Commit 2718a26

Browse files
committed
Fix constant optimization on RV32A instructions
Address a requirement to handle RV32A instructions that may perform register writes during constant optimization. As these instructions could potentially modify registers, it's essential to incorporate appropriate handling for such cases within constant optimization routines.
1 parent 8c1fc48 commit 2718a26

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

src/rv32_constopt.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -554,37 +554,67 @@ CONSTOPT(remu, {
554554
#if RV32_HAS(EXT_A)
555555

556556
/* LR.W: Load Reserved */
557-
CONSTOPT(lrw, {})
557+
CONSTOPT(lrw, {
558+
if (ir->rd)
559+
info->is_constant[ir->rd] = false;
560+
})
558561

559562
/* SC.W: Store Conditional */
560563
CONSTOPT(scw, {})
561564

562565
/* AMOSWAP.W: Atomic Swap */
563-
CONSTOPT(amoswapw, {})
566+
CONSTOPT(amoswapw, {
567+
if (ir->rd)
568+
info->is_constant[ir->rd] = false;
569+
})
564570

565571
/* AMOADD.W: Atomic ADD */
566-
CONSTOPT(amoaddw, {})
572+
CONSTOPT(amoaddw, {
573+
if (ir->rd)
574+
info->is_constant[ir->rd] = false;
575+
})
567576

568577
/* AMOXOR.W: Atomic XOR */
569-
CONSTOPT(amoxorw, {})
578+
CONSTOPT(amoxorw, {
579+
if (ir->rd)
580+
info->is_constant[ir->rd] = false;
581+
})
570582

571583
/* AMOAND.W: Atomic AND */
572-
CONSTOPT(amoandw, {})
584+
CONSTOPT(amoandw, {
585+
if (ir->rd)
586+
info->is_constant[ir->rd] = false;
587+
})
573588

574589
/* AMOOR.W: Atomic OR */
575-
CONSTOPT(amoorw, {})
590+
CONSTOPT(amoorw, {
591+
if (ir->rd)
592+
info->is_constant[ir->rd] = false;
593+
})
576594

577595
/* AMOMIN.W: Atomic MIN */
578-
CONSTOPT(amominw, {})
596+
CONSTOPT(amominw, {
597+
if (ir->rd)
598+
info->is_constant[ir->rd] = false;
599+
})
579600

580601
/* AMOMAX.W: Atomic MAX */
581-
CONSTOPT(amomaxw, {})
602+
CONSTOPT(amomaxw, {
603+
if (ir->rd)
604+
info->is_constant[ir->rd] = false;
605+
})
582606

583607
/* AMOMINU.W */
584-
CONSTOPT(amominuw, {})
608+
CONSTOPT(amominuw, {
609+
if (ir->rd)
610+
info->is_constant[ir->rd] = false;
611+
})
585612

586613
/* AMOMAXU.W */
587-
CONSTOPT(amomaxuw, {})
614+
CONSTOPT(amomaxuw, {
615+
if (ir->rd)
616+
info->is_constant[ir->rd] = false;
617+
})
588618
#endif /* RV32_HAS(EXT_A) */
589619

590620
/* RV32F Standard Extension */

0 commit comments

Comments
 (0)