mirror of
https://github.com/cc65/cc65.git
synced 2025-08-14 14:26:27 +00:00
Fixed a bug in the optimizer. Loads of X and Y from memory were sometimes
replaced by loads of A with an immediate value (which is stored in said memory location). git-svn-id: svn://svn.cc65.org/cc65/trunk@3813 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -1312,8 +1312,9 @@ unsigned OptPrecalc (CodeSeg* S)
|
|||||||
/* Get a pointer to the output registers of the insn */
|
/* Get a pointer to the output registers of the insn */
|
||||||
const RegContents* Out = &E->RI->Out;
|
const RegContents* Out = &E->RI->Out;
|
||||||
|
|
||||||
/* Argument for LDA and flag */
|
/* Argument for LDn and flag */
|
||||||
const char* Arg = 0;
|
const char* Arg = 0;
|
||||||
|
opc_t OPC = OP65_LDA;
|
||||||
|
|
||||||
/* Handle the different instructions */
|
/* Handle the different instructions */
|
||||||
switch (E->OPC) {
|
switch (E->OPC) {
|
||||||
@@ -1327,15 +1328,17 @@ unsigned OptPrecalc (CodeSeg* S)
|
|||||||
|
|
||||||
case OP65_LDX:
|
case OP65_LDX:
|
||||||
if (E->AM != AM65_IMM && RegValIsKnown (Out->RegX)) {
|
if (E->AM != AM65_IMM && RegValIsKnown (Out->RegX)) {
|
||||||
/* Result of load is known */
|
/* Result of load is known but register is X */
|
||||||
Arg = MakeHexArg (Out->RegX);
|
Arg = MakeHexArg (Out->RegX);
|
||||||
|
OPC = OP65_LDX;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OP65_LDY:
|
case OP65_LDY:
|
||||||
if (E->AM != AM65_IMM && RegValIsKnown (Out->RegY)) {
|
if (E->AM != AM65_IMM && RegValIsKnown (Out->RegY)) {
|
||||||
/* Result of load is known */
|
/* Result of load is known but register is Y */
|
||||||
Arg = MakeHexArg (Out->RegY);
|
Arg = MakeHexArg (Out->RegY);
|
||||||
|
OPC = OP65_LDY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1379,7 +1382,7 @@ unsigned OptPrecalc (CodeSeg* S)
|
|||||||
|
|
||||||
/* Check if we have to replace the insn by LDA */
|
/* Check if we have to replace the insn by LDA */
|
||||||
if (Arg) {
|
if (Arg) {
|
||||||
CodeEntry* X = NewCodeEntry (OP65_LDA, AM65_IMM, Arg, 0, E->LI);
|
CodeEntry* X = NewCodeEntry (OPC, AM65_IMM, Arg, 0, E->LI);
|
||||||
CS_InsertEntry (S, X, I+1);
|
CS_InsertEntry (S, X, I+1);
|
||||||
CS_DelEntry (S, I);
|
CS_DelEntry (S, I);
|
||||||
++Changes;
|
++Changes;
|
||||||
|
Reference in New Issue
Block a user