--- a/src/ASMText2.cpp +++ b/src/ASMText2.cpp @@ -1517,8 +1517,9 @@ } -// Remove AND, OR, MUL or ADD operations if we can show that -// they will not change performance of the program. +// ADD #0 can be an explicit condition-code test. Leave it to rules that +// prove which flags the surrounding instructions produce and consume. +// In particular, a called runtime helper may read the flags on entry. bool ASMText::removeAndOrMulAddSub(size_t index) { @@ -1588,42 +1589,6 @@ commentOut(index, "optim: removeAndOrMulAddSub case 5"); madeChanges = true; } - } else if ((instr == "ADDA") || (instr == "ADDB") || (instr == "ADDD")) { - if ((instr[3] == 'A' && simulator.regs.accum.a.known && simulator.regs.accum.a.val == 0) && - (instr[3] == 'B' && simulator.regs.accum.b.known && simulator.regs.accum.b.val == 0) && - (instr[3] == 'D' && simulator.regs.accum.dknown() && simulator.regs.accum.dval() == 0)) { - // We know that A, B or D are zero, so change to a LD - const Element &e1 = elements[index + 1]; - if (e1.type != INSTR || !isBasicBlockEndingInstruction(e1)) { - char newInstr[8]; - snprintf(newInstr, sizeof(newInstr), "LD%s", instr.c_str() + 3); - replaceWithInstr(index, newInstr, oper, "optim: removeAndOrMulAddSub case 6"); - madeChanges = true; - } - } else if (extractConstantLiteral(e.fields[1], val)) { - // We know that the operand is a constant 0 and the side effects are not valued, - // so we can comment it out - const Element &e1 = elements[index + 1]; - if (val == 0 && (e1.type == INSTR && !isBasicBlockEndingInstruction(e1))) { - InsEffects effects(e1); - if (!(effects.read & CC)) { - commentOut(index, "optim: removeAndOrMulAddSub case 7"); - madeChanges = true; - } - } else if (val == 0 && e1.type == INSTR && isBasicBlockEndingInstruction(e1) && - (((instr[3] == 'D') && (simulator.regs.accum.a.known && simulator.regs.accum.a.val == 0)) || - (instr[3] == 'B'))) { - // ADDD #0 and A is definitely zero or ADDB #0 so replace with TSTB - replaceWithInstr(index, "TSTB", "", "optim: removeAndOrMulAddSub case 8"); - madeChanges = true; - } else if (val == 0 && e1.type == INSTR && isBasicBlockEndingInstruction(e1) && - (((instr[3] == 'D') && (simulator.regs.accum.b.known && simulator.regs.accum.b.val == 0)) || - (instr[3] == 'A'))) { - // ADDD #0 and B is definitely zero or ADDA #0 so replace with TSTA - replaceWithInstr(index, "TSTA", "", "optim: removeAndOrMulAddSub case 9"); - madeChanges = true; - } - } } else if ((instr == "LEAX") && (oper == "D,X")) { if (simulator.regs.accum.dknown() && simulator.regs.accum.dval() == 0) { commentOut(index, "optim: removeAndOrMulAddSub case 10");