impemented #1914251, #1914245, #1922090, #1921382, #1918323, use 16-bit addition...
[fw/sdcc] / src / z80 / peeph-z80.def
index f717847ad2a11dd08f784864a7cbd5d78ba05909..bb740d2a5a4e0db04d5bb2db8d18f6204097b352 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+// This can't go into peeph.def since %1 could be (hl+) on gbz80.
+replace restart {
+       ld      %1,%3
+       ld      %1,%2
+} by {
+       ; peephole z0 removed dead load into %1
+       ld      %1,%2
+} if notVolatile(%1 %3), operandsNotSame
+
 replace restart {
        ld      %1,#%2
        ld      a,0(%1)
@@ -151,22 +160,31 @@ replace restart {
        jp      %1,%5
 } by {
        ret     %1
-       ; peephole z12 replaced jump by return.
+       ; peephole z11a replaced jump by return.
 } if labelIsReturnOnly(), labelRefCountChange(%5 -1)
 
 // Should be one of the last ones. Opens the code to further peephole optimization.
 replace restart {
 %1:
 } by {
-       ; peephole z13 removed unused label %1.
+       ; peephole z12 removed unused label %1.
 } if labelRefCount(%1 0)
 
+// Applying z11 or z11a followed by z12 will often leave a dead ret at the end of the function. Remove it.
+replace {
+       jp      %5
+       ret
+} by {
+       jp      %5
+       ; peephole z13 removed unused ret.
+}
+
 // These should be the last rules, so that the peepholes above need to look at jp only.
 replace {
        jp      %5
 } by {
        jr      %5
-       ; peephole z14 changed absolute to relative conditional jump.
+       ; peephole z14 changed absolute to relative unconditional jump.
 } if labelInRange()
 
 replace {