From d5fc69d3e4624c43a28e2816bdea0bd4071c9479 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 19 Oct 2024 14:45:53 +0200 Subject: [PATCH] fix instruction index error in optimizer --- .../src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt index cca83b3a0..140fe8012 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt @@ -64,7 +64,7 @@ class IRPeepholeOptimizer(private val irprog: IRProgram) { private fun replaceConcatZeroMsbWithExt(chunk: IRCodeChunk, indexedInstructions: List>): Boolean { var changed = false indexedInstructions.reversed().forEach { (idx, ins) -> - if (ins.opcode == Opcode.CONCAT) { + if (ins.opcode == Opcode.CONCAT && idx>0) { // if the previous instruction loads a zero in the msb, this can be turned into EXT.B instead val prev = indexedInstructions[idx-1].value if(prev.opcode==Opcode.LOAD && prev.immediate==0 && prev.reg1==ins.reg2) { @@ -449,7 +449,7 @@ class IRPeepholeOptimizer(private val irprog: IRProgram) { private fun removeDoubleLoadsAndStores(chunk: IRCodeChunk, indexedInstructions: List>): Boolean { var changed = false indexedInstructions.forEach { (idx, ins) -> - if(ins.opcode==Opcode.STOREM) { + if(ins.opcode==Opcode.STOREM && idx>0) { val prev = indexedInstructions[idx-1].value if(prev.opcode==Opcode.LOADM) { // loadm.X rX,something | storem.X rX,something ?? -> get rid of the store.