IR: fix LOADI.f peephole optimization

This commit is contained in:
Irmen de Jong
2026-01-09 03:49:10 +01:00
parent f69b293b7f
commit 13cd68ba96
2 changed files with 17 additions and 5 deletions
@@ -605,11 +605,18 @@ jump p8_label_gen_2
if((load.opcode==Opcode.LOAD) && load.labelSymbol!=null) {
val lastInstruction = indexedInstructions[idx+1].value
if(lastInstruction.opcode==Opcode.LOADI) {
val targetRegister = lastInstruction.reg1!!
if(lastInstruction.type== IRDataType.FLOAT) {
TODO("peephole opt LOADI.float")
if(ins.reg1==lastInstruction.reg1!! && load.reg1==lastInstruction.reg1!!) {
val targetFpRegister = lastInstruction.fpReg1!!
val loadm = IRInstruction(Opcode.LOADM, lastInstruction.type, fpReg1 = targetFpRegister, labelSymbol = load.labelSymbol, symbolOffset = ins.immediate)
chunk.instructions[idx-1] = loadm
chunk.instructions.removeAt(idx+1)
chunk.instructions.removeAt(idx)
changed = true
}
} else {
if(ins.reg1==lastInstruction.reg2!! && load.reg1==lastInstruction.reg2!!) {
val targetRegister = lastInstruction.reg1!!
val loadm = IRInstruction(Opcode.LOADM, lastInstruction.type, reg1=targetRegister, labelSymbol = load.labelSymbol, symbolOffset = ins.immediate)
chunk.instructions[idx-1] = loadm
chunk.instructions.removeAt(idx+1)
@@ -618,12 +625,14 @@ jump p8_label_gen_2
}
}
} else if(lastInstruction.opcode==Opcode.STOREI) {
val valueLoad = indexedInstructions[idx-2].value
val targetRegister = lastInstruction.reg1!!
if(lastInstruction.type==IRDataType.FLOAT) {
TODO("peephole opt STOREI.float")
if(ins.reg1==lastInstruction.reg1!! && load.reg1==lastInstruction.reg1!!) {
TODO("peephole opt STOREI.float ${chunk.sourceLinesPositions}")
}
} else {
if(ins.reg1==lastInstruction.reg2!! && load.reg1==lastInstruction.reg2!!) {
val valueLoad = indexedInstructions[idx-2].value
if(valueLoad.opcode==Opcode.LOAD && valueLoad.reg1==targetRegister) {
val storem = IRInstruction(Opcode.STOREM, lastInstruction.type, reg1=valueLoad.reg1, labelSymbol = load.labelSymbol, symbolOffset = ins.immediate)
chunk.instructions[idx-1] = storem