Skip to content

Commit a33e79e

Browse files
AJBatsclaude
andcommitted
delay-slot filler: reject candidates sitting in another branch's slot
sh_fill_branch_delays would chain-walk a delay-slot instruction OUT of an earlier branch's slot to fill a later one. When the killed line was the only thing between two branches, the lexical neighbour after the emitted-stream collapse silently slid into the now-vacated slot — and when that neighbour was itself a branch, we shipped a `bra` (or other branch) literally inside a `jsr` delay slot. That's forbidden by the SH7604 spec ("any branch, MOVA, or TRAPA in a delay slot is illegal"). HEAD's checked-in FUN_06040EA0.s line 60 was a concrete example. Guard: before accepting candidate k, walk back one non-empty line; if that's a branch, k is in its delay slot — refuse. Two effects: 1. IPA Phase E.1b regtest now passes end-to-end. The synthesized `add drh#16, r4` lands in jsr 1's delay slot (executed before the branch fires, so both helpers see r4 = p1+16); the chain-walk used to displace it past both calls into dead-code territory. Also fixes an awk bug in the regtest itself: the prior pattern `flag; /^_[a-zA-Z]/{if(seen)exit; seen=1}` exited at the FIRST `_<letter>:` label (which is `_helper_a:`, drained before `_caller:` in source order), so caller_body was always empty and the test always failed regardless of compiler output. 2. Cleans up illegal-SH-2 emissions across the corpus. Net byte- match impact: 4 functions improved (FUN_06040EA0 standalone + FUN_06045378, FUN_060477FC, FUN_06047A08 in TU), 17 functions drift +1 to +4 bytes (all in functions already 22..1024 bytes off prod — line-shift noise, none breaking byte-match). The improvements include cases where the chain-walk's illegal output was the only thing keeping us from matching prod's spec-correct sequencing. No previously byte-matched (diff=0) function regressed. The IPA mechanism itself is unchanged — this is a pre-existing filler bug that the IPA test happened to surface because the synthesized add is exactly the kind of instruction the chain-walk likes to grab. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 943a487 commit a33e79e

5 files changed

Lines changed: 164 additions & 21 deletions

File tree

saturn/experiments/daytona_byte_match/race_FUN_06044060/FUN_06044060.s

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9669,17 +9669,22 @@ _FUN_060451bc:
96699669
mov.l L2716,r4
96709670
mov.l L2717,r3
96719671
jsr @r3
9672+
mov.l @r4,r4
96729673
mov.l L2718,r3
96739674
jsr @r3
9675+
nop
96749676
mov.l L2719,r3
96759677
jsr @r3
9678+
nop
96769679
mov.l L2720,r3
96779680
jsr @r3
9681+
nop
96789682
mov.l L2721,r3
96799683
jsr @r3
9684+
nop
96809685
lds.l @r15+,pr
96819686
rts
9682-
mov.l @r4,r4
9687+
nop
96839688
.align 2
96849689
L2716: .long _uRam060451f4
96859690
L2717: .long _func_0x06044d80
@@ -11846,9 +11851,10 @@ _FUN_06045368:
1184611851
mov.l L2792,r3
1184711852
mov.l @r4,r4
1184811853
jsr @r3
11854+
mov.l @r4,r4
1184911855
mov.l L2793,r3
1185011856
jsr @r3
11851-
mov.l @r4,r4
11857+
nop
1185211858
mov.l L2794,r3
1185311859
jsr @r3
1185411860
lds.l @r15+,pr
@@ -11874,9 +11880,10 @@ _FUN_06045378:
1187411880
mov.l L2796,r3
1187511881
mov.l @r4,r4
1187611882
jsr @r3
11883+
mov.l @r4,r4
1187711884
mov.l L2798,r3
1187811885
jsr @r3
11879-
mov.l @r4,r4
11886+
nop
1188011887
mov.l L2799,r3
1188111888
jsr @r3
1188211889
lds.l @r15+,pr
@@ -14299,9 +14306,10 @@ L1763:
1429914306
add r9,r0
1430014307
mov.l L3008,r3
1430114308
jsr @r3
14309+
mov.l r14,@r0
1430214310
mov.l L3009,r3
1430314311
jsr @r3
14304-
mov.l r14,@r0
14312+
nop
1430514313
mov.w L3007,r4
1430614314
add r9,r4
1430714315
mov.l L3010,r3
@@ -14379,9 +14387,10 @@ L1770:
1437914387
add r9,r0
1438014388
mov.l L3016,r3
1438114389
jsr @r3
14390+
mov.l r14,@r0
1438214391
mov.l L3017,r3
1438314392
jsr @r3
14384-
mov.l r14,@r0
14393+
nop
1438514394
mov.w L3015,r4
1438614395
add r9,r4
1438714396
mov.l L3018,r3
@@ -14439,9 +14448,10 @@ L1775:
1443914448
add r11,r0
1444014449
mov.l L3024,r3
1444114450
jsr @r3
14451+
mov.l r14,@r0
1444214452
mov.l L3025,r3
1444314453
jsr @r3
14444-
mov.l r14,@r0
14454+
nop
1444514455
mov.w L3023,r4
1444614456
add r11,r4
1444714457
mov.l L3026,r3
@@ -14499,9 +14509,10 @@ L1780:
1449914509
add r11,r0
1450014510
mov.l L3032,r3
1450114511
jsr @r3
14512+
mov.l r14,@r0
1450214513
mov.l L3033,r3
1450314514
jsr @r3
14504-
mov.l r14,@r0
14515+
nop
1450514516
mov.w L3031,r4
1450614517
add r11,r4
1450714518
mov.l L3034,r3
@@ -14559,9 +14570,10 @@ L1785:
1455914570
add r11,r0
1456014571
mov.l L3040,r3
1456114572
jsr @r3
14573+
mov.l r14,@r0
1456214574
mov.l L3041,r3
1456314575
jsr @r3
14564-
mov.l r14,@r0
14576+
nop
1456514577
mov.w L3039,r4
1456614578
add r11,r4
1456714579
mov.l L3042,r3
@@ -14619,9 +14631,10 @@ L1790:
1461914631
add r11,r0
1462014632
mov.l L3048,r3
1462114633
jsr @r3
14634+
mov.l r14,@r0
1462214635
mov.l L3049,r3
1462314636
jsr @r3
14624-
mov.l r14,@r0
14637+
nop
1462514638
mov.w L3047,r4
1462614639
add r11,r4
1462714640
mov.l L3050,r3
@@ -15802,6 +15815,7 @@ L1898:
1580215815
mov.l L3105,r3
1580315816
jsr @r3
1580415817
mov.w r0,@(4,r10)
15818+
nop
1580515819
add #4,r15
1580615820
lds.l @r15+,pr
1580715821
rts
@@ -17173,6 +17187,7 @@ L2002:
1717317187
mov.l L3219,r3
1717417188
jsr @r3
1717517189
mov #4,r4
17190+
nop
1717617191
add #32,r15
1717717192
lds.l @r15+,pr
1717817193
rts
@@ -17285,6 +17300,7 @@ L2007:
1728517300
mov.l L3228,r3
1728617301
jsr @r3
1728717302
mov #4,r4
17303+
nop
1728817304
add #20,r15
1728917305
lds.l @r15+,pr
1729017306
rts
@@ -17299,6 +17315,7 @@ L2011:
1729917315
mov.l L3229,r3
1730017316
jsr @r3
1730117317
mov.l @r4,r4
17318+
nop
1730217319
add #20,r15
1730317320
lds.l @r15+,pr
1730417321
rts
@@ -17376,6 +17393,7 @@ L2017:
1737617393
mov.l L3234,r3
1737717394
jsr @r3
1737817395
mov.b r1,@r0
17396+
nop
1737917397
add #4,r15
1738017398
lds.l @r15+,pr
1738117399
rts
@@ -17416,6 +17434,7 @@ L2021:
1741617434
mov.l L3238,r3
1741717435
jsr @r3
1741817436
mov #3,r4
17437+
nop
1741917438
add #4,r15
1742017439
lds.l @r15+,pr
1742117440
rts
@@ -17426,13 +17445,15 @@ L2023:
1742617445
mov #4,r1
1742717446
mov.l L3239,r3
1742817447
jsr @r3
17448+
mov.b r1,@r0
1742917449
mov.l L3240,r3
1743017450
jsr @r3
17451+
nop
1743117452
L2013:
1743217453
add #4,r15
1743317454
lds.l @r15+,pr
1743417455
rts
17435-
mov.b r1,@r0
17456+
nop
1743617457
.align 2
1743717458
L3233: .short 155
1743817459
.align 2
@@ -17477,6 +17498,7 @@ _FUN_06046a24:
1747717498
mov.l L3245,r3
1747817499
jsr @r3
1747917500
mov.b r1,@r0
17501+
nop
1748017502
lds.l @r15+,pr
1748117503
rts
1748217504
nop
@@ -17510,6 +17532,7 @@ L2026:
1751017532
mov.l L3249,r3
1751117533
jsr @r3
1751217534
mov #3,r4
17535+
nop
1751317536
lds.l @r15+,pr
1751417537
rts
1751517538
nop
@@ -17519,9 +17542,11 @@ L2030:
1751917542
mov #4,r1
1752017543
mov.l L3250,r3
1752117544
jsr @r3
17545+
mov.b r1,@r0
1752217546
mov.l L3251,r3
1752317547
jsr @r3
17524-
mov.b r1,@r0
17548+
nop
17549+
nop
1752517550
lds.l @r15+,pr
1752617551
rts
1752717552
nop
@@ -17573,6 +17598,7 @@ _FUN_06046a90:
1757317598
mov.l L3256,r3
1757417599
jsr @r3
1757517600
mov.b r1,@r0
17601+
nop
1757617602
lds.l @r15+,pr
1757717603
rts
1757817604
nop
@@ -17650,6 +17676,7 @@ _FUN_06046ae8:
1765017676
mov.l L3264,r3
1765117677
jsr @r3
1765217678
mov.b r1,@r0
17679+
nop
1765317680
lds.l @r15+,pr
1765417681
rts
1765517682
nop
@@ -18272,9 +18299,10 @@ _FUN_06046e0e:
1827218299
add r12,r0
1827318300
mov.l L3278,r3
1827418301
jsr @r3
18302+
mov.l r13,@r0
1827518303
mov.l L3279,r3
1827618304
jsr @r3
18277-
mov.l r13,@r0
18305+
nop
1827818306
mov.w L3280,r0
1827918307
add r12,r0
1828018308
mov.b @r0,r0
@@ -18319,9 +18347,10 @@ _FUN_06046e64:
1831918347
add r12,r0
1832018348
mov.l L3285,r3
1832118349
jsr @r3
18350+
mov.l r13,@r0
1832218351
mov.l L3286,r3
1832318352
jsr @r3
18324-
mov.l r13,@r0
18353+
nop
1832518354
mov.w L3287,r0
1832618355
add r12,r0
1832718356
mov.b @r0,r0
@@ -20290,6 +20319,7 @@ _FUN_060477fc:
2029020319
mov.l @r0,r0
2029120320
jsr @r3
2029220321
mov r4,r5
20322+
nop
2029320323
lds.l @r15+,pr
2029420324
rts
2029520325
nop
@@ -20601,9 +20631,10 @@ _FUN_06047a08:
2060120631
mov #1,r1
2060220632
mov.l L3449,r3
2060320633
jsr @r3
20634+
mov.l r1,@r0
2060420635
mov.l L3450,r3
2060520636
jsr @r3
20606-
mov.l r1,@r0
20637+
nop
2060720638
mov.l L3451,r0
2060820639
mov.w @r0,r0
2060920640
mov.w r0,@r11

saturn/experiments/daytona_byte_match/race_tu1/FUN_06037E28.s

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ Lswt0:
215215
mov r14,r4
216216
mov.l L64,r0
217217
jsr @r0
218-
bra L9
219218
mov r14,r4
219+
bra L9
220+
nop
220221
.align 2
221222
L49: .long _sub_06038014
222223
L50: .long _sub_06038018
@@ -352,8 +353,9 @@ L66: .long _sub_06038390
352353
mov r14,r4
353354
mov.l L71,r0
354355
jsr @r0
355-
bra L9
356356
mov r14,r4
357+
bra L9
358+
nop
357359
.align 2
358360
L97: .short -3
359361
L98: .short -2
@@ -537,8 +539,9 @@ L19:
537539
nop
538540
mov.l L82,r0
539541
jsr @r0
540-
bra L9
541542
mov r14,r4
543+
bra L9
544+
nop
542545
.align 2
543546
L73: .short 424
544547
L76: .short 224
@@ -551,6 +554,7 @@ L114: .short -65
551554
L77: .long _sub_06038260
552555
L79: .long _sub_06038264
553556
L80: .long _sub_06038268
557+
L101: .long _FUN_060384c4
554558
mov.l L83,r0
555559
jsr @r0
556560
mov r14,r4
@@ -569,7 +573,6 @@ L80: .long _sub_06038268
569573
L108: .short 128
570574
.align 2
571575
L74: .long 3129907
572-
L101: .long _FUN_060384c4
573576
L25:
574577
mov.w L109,r14
575578
L26:
@@ -620,8 +623,9 @@ L26:
620623
nop
621624
mov.l L87,r0
622625
jsr @r0
623-
bra L9
624626
mov r14,r4
627+
bra L9
628+
nop
625629
.align 2
626630
L109: .short 224
627631
.align 2
@@ -663,6 +667,7 @@ L96: .long _FUN_06038dd8
663667
nop
664668
.align 2
665669
L102: .long _func_06038a82
670+
L103: .long _func_060385ce
666671
mov r14,r0
667672
mov.w L110,r1
668673
add r1,r0
@@ -947,7 +952,6 @@ L92: .long -134217729
947952
L93: .long 101001168
948953
L94: .long 101001172
949954
L95: .long 101007540
950-
L103: .long _func_060385ce
951955
L104: .long _func_060386d8
952956
L105: .long _FUN_06038c64
953957
L106: .long _func_06038bc4

saturn/experiments/daytona_byte_match/race_tu1/FUN_06040EA0.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ _FUN_06040EA0:
5757
mov r0,r5
5858
mov.l L20,r0
5959
jsr @r0
60-
bra L12
6160
mov #32,r6
61+
bra L12
62+
nop
6263
L8:
6364
L6:
6465
mov.l @(48,gbr),r0

0 commit comments

Comments
 (0)