mirror of
https://github.com/KarolS/millfork.git
synced 2024-10-25 05:24:11 +00:00
Fix for a bug in the variable-to-register optimization
This commit is contained in:
parent
3c3ac9d70e
commit
0f354d2f14
@ -53,6 +53,9 @@ object VariableToRegisterOptimization extends AssemblyOptimization {
|
|||||||
AHX, SHY, SHX, LAS, TAS,
|
AHX, SHY, SHX, LAS, TAS,
|
||||||
TRB, TSB)
|
TRB, TSB)
|
||||||
|
|
||||||
|
private val LdxAddrModes = Set(ZeroPage, Absolute, Immediate, AbsoluteY, ZeroPageY)
|
||||||
|
private val LdyAddrModes = Set(ZeroPage, Absolute, Immediate, AbsoluteX, ZeroPageX)
|
||||||
|
|
||||||
override def name = "Allocating variables to index registers"
|
override def name = "Allocating variables to index registers"
|
||||||
|
|
||||||
|
|
||||||
@ -543,12 +546,12 @@ object VariableToRegisterOptimization extends AssemblyOptimization {
|
|||||||
AssemblyLine.implied(TAY) :: inlineVars(xCandidate, yCandidate, aCandidate, xs)
|
AssemblyLine.implied(TAY) :: inlineVars(xCandidate, yCandidate, aCandidate, xs)
|
||||||
|
|
||||||
case (AssemblyLine(LDA, am, param, true), _) :: (AssemblyLine(STA, Absolute | ZeroPage, MemoryAddressConstant(th), true), _) :: xs
|
case (AssemblyLine(LDA, am, param, true), _) :: (AssemblyLine(STA, Absolute | ZeroPage, MemoryAddressConstant(th), true), _) :: xs
|
||||||
if th.name == vx && doesntUseX(am) =>
|
if th.name == vx && LdxAddrModes(am) =>
|
||||||
// these TXA's may get optimized away by a different optimization
|
// these TXA's may get optimized away by a different optimization
|
||||||
AssemblyLine(LDX, am, param) :: AssemblyLine.implied(TXA) :: inlineVars(xCandidate, yCandidate, aCandidate, xs)
|
AssemblyLine(LDX, am, param) :: AssemblyLine.implied(TXA) :: inlineVars(xCandidate, yCandidate, aCandidate, xs)
|
||||||
|
|
||||||
case (AssemblyLine(LDA, am, param, true), _) :: (AssemblyLine(STA, Absolute | ZeroPage, MemoryAddressConstant(th), true), _) :: xs
|
case (AssemblyLine(LDA, am, param, true), _) :: (AssemblyLine(STA, Absolute | ZeroPage, MemoryAddressConstant(th), true), _) :: xs
|
||||||
if th.name == vy && doesntUseY(am) =>
|
if th.name == vy && LdyAddrModes(am) =>
|
||||||
// these TYA's may get optimized away by a different optimization
|
// these TYA's may get optimized away by a different optimization
|
||||||
AssemblyLine(LDY, am, param) :: AssemblyLine.implied(TYA) :: inlineVars(xCandidate, yCandidate, aCandidate, xs)
|
AssemblyLine(LDY, am, param) :: AssemblyLine.implied(TYA) :: inlineVars(xCandidate, yCandidate, aCandidate, xs)
|
||||||
|
|
||||||
@ -624,16 +627,6 @@ object VariableToRegisterOptimization extends AssemblyOptimization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def doesntUseY(am: AddrMode.Value): Boolean = am match {
|
|
||||||
case AbsoluteY | ZeroPageY | IndexedY => false
|
|
||||||
case _ => true
|
|
||||||
}
|
|
||||||
|
|
||||||
def doesntUseX(am: AddrMode.Value): Boolean = am match {
|
|
||||||
case AbsoluteX | ZeroPageX | IndexedX | AbsoluteIndexedX => false
|
|
||||||
case _ => true
|
|
||||||
}
|
|
||||||
|
|
||||||
def doesntUseXOrY(am: AddrMode.Value): Boolean = am match {
|
def doesntUseXOrY(am: AddrMode.Value): Boolean = am match {
|
||||||
case Immediate | ZeroPage | Absolute | Relative | Indirect | ZeroPageIndirect => true
|
case Immediate | ZeroPage | Absolute | Relative | Indirect | ZeroPageIndirect => true
|
||||||
case _ => false
|
case _ => false
|
||||||
|
Loading…
Reference in New Issue
Block a user