summaryrefslogtreecommitdiff
path: root/src/jit/regalloc.cpp
blob: a9119945d93cfd53cfc64cb001a9692fdd82c7a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX                                                                           XX
XX                           RegAlloc                                        XX
XX                                                                           XX
XX  Does the register allocation and puts the remaining lclVars on the stack XX
XX                                                                           XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

#include "jitpch.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#include "regalloc.h"

#if FEATURE_FP_REGALLOC
Compiler::enumConfigRegisterFP Compiler::raConfigRegisterFP()
{
    DWORD val = JitConfig.JitRegisterFP();

    return (enumConfigRegisterFP)(val & 0x3);
}
#endif // FEATURE_FP_REGALLOC

regMaskTP Compiler::raConfigRestrictMaskFP()
{
    regMaskTP result = RBM_NONE;

#if FEATURE_FP_REGALLOC
    switch (raConfigRegisterFP())
    {
        case CONFIG_REGISTER_FP_NONE:
            result = RBM_NONE;
            break;
        case CONFIG_REGISTER_FP_CALLEE_TRASH:
            result = RBM_FLT_CALLEE_TRASH;
            break;
        case CONFIG_REGISTER_FP_CALLEE_SAVED:
            result = RBM_FLT_CALLEE_SAVED;
            break;
        case CONFIG_REGISTER_FP_FULL:
            result = RBM_ALLFLOAT;
            break;
    }
#endif

    return result;
}

#if DOUBLE_ALIGN
DWORD Compiler::getCanDoubleAlign()
{
#ifdef DEBUG
    if (compStressCompile(STRESS_DBL_ALN, 20))
        return MUST_DOUBLE_ALIGN;

    return JitConfig.JitDoubleAlign();
#else
    return DEFAULT_DOUBLE_ALIGN;
#endif
}

//------------------------------------------------------------------------
// shouldDoubleAlign: Determine whether to double-align the frame
//
// Arguments:
//    refCntStk       - sum of     ref counts for all stack based variables
//    refCntEBP       - sum of     ref counts for EBP enregistered variables
//    refCntWtdEBP    - sum of wtd ref counts for EBP enregistered variables
//    refCntStkParam  - sum of     ref counts for all stack based parameters
//    refCntWtdStkDbl - sum of wtd ref counts for stack based doubles (including structs
//                      with double fields).
//
// Return Value:
//    Returns true if this method estimates that a double-aligned frame would be beneficial
//
// Notes:
//    The impact of a double-aligned frame is computed as follows:
//    - We save a byte of code for each parameter reference (they are frame-pointer relative)
//    - We pay a byte of code for each non-parameter stack reference.
//    - We save the misalignment penalty and possible cache-line crossing penalty.
//      This is estimated as 0 for SMALL_CODE, 16 for FAST_CODE and 4 otherwise.
//    - We pay 7 extra bytes for:
//        MOV EBP,ESP,
//        LEA ESP,[EBP-offset]
//        AND ESP,-8 to double align ESP
//    - We pay one extra memory reference for each variable that could have been enregistered in EBP (refCntWtdEBP).
//
//    If the misalignment penalty is estimated to be less than the bytes used, we don't double align.
//    Otherwise, we compare the weighted ref count of ebp-enregistered variables aginst double the
//    ref count for double-aligned values.
//
bool Compiler::shouldDoubleAlign(
    unsigned refCntStk, unsigned refCntEBP, unsigned refCntWtdEBP, unsigned refCntStkParam, unsigned refCntWtdStkDbl)
{
    bool           doDoubleAlign        = false;
    const unsigned DBL_ALIGN_SETUP_SIZE = 7;

    unsigned bytesUsed         = refCntStk + refCntEBP - refCntStkParam + DBL_ALIGN_SETUP_SIZE;
    unsigned misaligned_weight = 4;

    if (compCodeOpt() == Compiler::SMALL_CODE)
        misaligned_weight = 0;

    if (compCodeOpt() == Compiler::FAST_CODE)
        misaligned_weight *= 4;

    JITDUMP("\nDouble alignment:\n");
    JITDUMP("  Bytes that could be saved by not using EBP frame: %i\n", bytesUsed);
    JITDUMP("  Sum of weighted ref counts for EBP enregistered variables: %i\n", refCntWtdEBP);
    JITDUMP("  Sum of weighted ref counts for weighted stack based doubles: %i\n", refCntWtdStkDbl);

    if (bytesUsed > ((refCntWtdStkDbl * misaligned_weight) / BB_UNITY_WEIGHT))
    {
        JITDUMP("    Predicting not to double-align ESP to save %d bytes of code.\n", bytesUsed);
    }
    else if (refCntWtdEBP > refCntWtdStkDbl * 2)
    {
        // TODO-CQ: On P4 2 Proc XEON's, SciMark.FFT degrades if SciMark.FFT.transform_internal is
        // not double aligned.
        // Here are the numbers that make this not double-aligned.
        //     refCntWtdStkDbl = 0x164
        //     refCntWtdEBP    = 0x1a4
        // We think we do need to change the heuristic to be in favor of double-align.

        JITDUMP("    Predicting not to double-align ESP to allow EBP to be used to enregister variables.\n");
    }
    else
    {
        // OK we passed all of the benefit tests, so we'll predict a double aligned frame.
        JITDUMP("    Predicting to create a double-aligned frame\n");
        doDoubleAlign = true;
    }
    return doDoubleAlign;
}
#endif // DOUBLE_ALIGN

#ifdef LEGACY_BACKEND // We don't use any of the old register allocator functions when LSRA is used instead.

void Compiler::raInit()
{
#if FEATURE_STACK_FP_X87
    /* We have not assigned any FP variables to registers yet */

    VarSetOps::AssignNoCopy(this, optAllFPregVars, VarSetOps::UninitVal());
#endif
    codeGen->intRegState.rsIsFloat   = false;
    codeGen->floatRegState.rsIsFloat = true;

    rpReverseEBPenreg = false;
    rpAsgVarNum       = -1;
    rpPassesMax       = 6;
    rpPassesPessimize = rpPassesMax - 3;
    if (opts.compDbgCode)
    {
        rpPassesMax++;
    }
    rpStkPredict            = (unsigned)-1;
    rpFrameType             = FT_NOT_SET;
    rpLostEnreg             = false;
    rpMustCreateEBPCalled   = false;
    rpRegAllocDone          = false;
    rpMaskPInvokeEpilogIntf = RBM_NONE;

    rpPredictMap[PREDICT_NONE] = RBM_NONE;
    rpPredictMap[PREDICT_ADDR] = RBM_NONE;

#if FEATURE_FP_REGALLOC
    rpPredictMap[PREDICT_REG]         = RBM_ALLINT | RBM_ALLFLOAT;
    rpPredictMap[PREDICT_SCRATCH_REG] = RBM_ALLINT | RBM_ALLFLOAT;
#else
    rpPredictMap[PREDICT_REG]         = RBM_ALLINT;
    rpPredictMap[PREDICT_SCRATCH_REG] = RBM_ALLINT;
#endif

#define REGDEF(name, rnum, mask, sname) rpPredictMap[PREDICT_REG_##name] = RBM_##name;
#include "register.h"

#if defined(_TARGET_ARM_)

    rpPredictMap[PREDICT_PAIR_R0R1] = RBM_R0 | RBM_R1;
    rpPredictMap[PREDICT_PAIR_R2R3] = RBM_R2 | RBM_R3;
    rpPredictMap[PREDICT_REG_SP]    = RBM_ILLEGAL;

#elif defined(_TARGET_AMD64_)

    rpPredictMap[PREDICT_NOT_REG_EAX] = RBM_ALLINT & ~RBM_EAX;
    rpPredictMap[PREDICT_NOT_REG_ECX] = RBM_ALLINT & ~RBM_ECX;
    rpPredictMap[PREDICT_REG_ESP]     = RBM_ILLEGAL;

#elif defined(_TARGET_X86_)

    rpPredictMap[PREDICT_NOT_REG_EAX] = RBM_ALLINT & ~RBM_EAX;
    rpPredictMap[PREDICT_NOT_REG_ECX] = RBM_ALLINT & ~RBM_ECX;
    rpPredictMap[PREDICT_REG_ESP]     = RBM_ILLEGAL;
    rpPredictMap[PREDICT_PAIR_EAXEDX] = RBM_EAX | RBM_EDX;
    rpPredictMap[PREDICT_PAIR_ECXEBX] = RBM_ECX | RBM_EBX;

#endif

    rpBestRecordedPrediction = NULL;
}

/*****************************************************************************
 *
 *  The following table(s) determines the order in which registers are considered
 *  for variables to live in
 */

const regNumber* Compiler::raGetRegVarOrder(var_types regType, unsigned* wbVarOrderSize)
{
#if FEATURE_FP_REGALLOC
    if (varTypeIsFloating(regType))
    {
        static const regNumber raRegVarOrderFlt[]   = {REG_VAR_ORDER_FLT};
        const unsigned         raRegVarOrderFltSize = sizeof(raRegVarOrderFlt) / sizeof(raRegVarOrderFlt[0]);

        if (wbVarOrderSize != NULL)
            *wbVarOrderSize = raRegVarOrderFltSize;

        return &raRegVarOrderFlt[0];
    }
    else
#endif
    {
        static const regNumber raRegVarOrder[]   = {REG_VAR_ORDER};
        const unsigned         raRegVarOrderSize = sizeof(raRegVarOrder) / sizeof(raRegVarOrder[0]);

        if (wbVarOrderSize != NULL)
            *wbVarOrderSize = raRegVarOrderSize;

        return &raRegVarOrder[0];
    }
}

#ifdef DEBUG

/*****************************************************************************
 *
 *  Dump out the variable interference graph
 *
 */

void Compiler::raDumpVarIntf()
{
    unsigned   lclNum;
    LclVarDsc* varDsc;

    printf("Var. interference graph for %s\n", info.compFullName);

    for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
    {
        /* Ignore the variable if it's not tracked */

        if (!varDsc->lvTracked)
            continue;

        /* Get hold of the index and the interference mask for the variable */
        unsigned varIndex = varDsc->lvVarIndex;

        printf("  V%02u,T%02u and ", lclNum, varIndex);

        unsigned refIndex;

        for (refIndex = 0; refIndex < lvaTrackedCount; refIndex++)
        {
            if (VarSetOps::IsMember(this, lvaVarIntf[varIndex], refIndex))
                printf("T%02u ", refIndex);
            else
                printf("    ");
        }

        printf("\n");
    }

    printf("\n");
}

/*****************************************************************************
 *
 *  Dump out the register interference graph
 *
 */
void Compiler::raDumpRegIntf()
{
    printf("Reg. interference graph for %s\n", info.compFullName);

    unsigned   lclNum;
    LclVarDsc* varDsc;

    for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
    {
        unsigned varNum;

        /* Ignore the variable if it's not tracked */

        if (!varDsc->lvTracked)
            continue;

        /* Get hold of the index and the interference mask for the variable */

        varNum = varDsc->lvVarIndex;

        printf("  V%02u,T%02u and ", lclNum, varNum);

        if (varDsc->IsFloatRegType())
        {
#if !FEATURE_STACK_FP_X87
            for (regNumber regNum = REG_FP_FIRST; regNum <= REG_FP_LAST; regNum = REG_NEXT(regNum))
            {
                if (VarSetOps::IsMember(this, raLclRegIntf[regNum], varNum))
                    printf("%3s ", getRegName(regNum, true));
                else
                    printf("    ");
            }
#endif
        }
        else
        {
            for (regNumber regNum = REG_INT_FIRST; regNum <= REG_INT_LAST; regNum = REG_NEXT(regNum))
            {
                if (VarSetOps::IsMember(this, raLclRegIntf[regNum], varNum))
                    printf("%3s ", getRegName(regNum));
                else
                    printf("    ");
            }
        }

        printf("\n");
    }

    printf("\n");
}
#endif // DEBUG

/*****************************************************************************
 *
 * We'll adjust the ref counts based on interference
 *
 */

void Compiler::raAdjustVarIntf()
{
    // This method was not correct and has been disabled.
    return;
}

/*****************************************************************************/
/*****************************************************************************/
/* Determine register mask for a call/return from type.
 */

inline regMaskTP Compiler::genReturnRegForTree(GenTreePtr tree)
{
    var_types type = tree->TypeGet();

    if (type == TYP_STRUCT && IsHfa(tree))
    {
        int retSlots = GetHfaCount(tree);
        return ((1 << retSlots) - 1) << REG_FLOATRET;
    }

    const static regMaskTP returnMap[TYP_COUNT] = {
        RBM_ILLEGAL,   // TYP_UNDEF,
        RBM_NONE,      // TYP_VOID,
        RBM_INTRET,    // TYP_BOOL,
        RBM_INTRET,    // TYP_CHAR,
        RBM_INTRET,    // TYP_BYTE,
        RBM_INTRET,    // TYP_UBYTE,
        RBM_INTRET,    // TYP_SHORT,
        RBM_INTRET,    // TYP_USHORT,
        RBM_INTRET,    // TYP_INT,
        RBM_INTRET,    // TYP_UINT,
        RBM_LNGRET,    // TYP_LONG,
        RBM_LNGRET,    // TYP_ULONG,
        RBM_FLOATRET,  // TYP_FLOAT,
        RBM_DOUBLERET, // TYP_DOUBLE,
        RBM_INTRET,    // TYP_REF,
        RBM_INTRET,    // TYP_BYREF,
        RBM_INTRET,    // TYP_ARRAY,
        RBM_ILLEGAL,   // TYP_STRUCT,
        RBM_ILLEGAL,   // TYP_BLK,
        RBM_ILLEGAL,   // TYP_LCLBLK,
        RBM_ILLEGAL,   // TYP_PTR,
        RBM_ILLEGAL,   // TYP_FNC,
        RBM_ILLEGAL,   // TYP_UNKNOWN,
    };

    assert((unsigned)type < sizeof(returnMap) / sizeof(returnMap[0]));
    assert(returnMap[TYP_LONG] == RBM_LNGRET);
    assert(returnMap[TYP_DOUBLE] == RBM_DOUBLERET);
    assert(returnMap[TYP_REF] == RBM_INTRET);
    assert(returnMap[TYP_STRUCT] == RBM_ILLEGAL);

    regMaskTP result = returnMap[type];
    assert(result != RBM_ILLEGAL);
    return result;
}

/*****************************************************************************/

/****************************************************************************/

#ifdef DEBUG

static void dispLifeSet(Compiler* comp, VARSET_VALARG_TP mask, VARSET_VALARG_TP life)
{
    unsigned   lclNum;
    LclVarDsc* varDsc;

    for (lclNum = 0, varDsc = comp->lvaTable; lclNum < comp->lvaCount; lclNum++, varDsc++)
    {
        if (!varDsc->lvTracked)
            continue;

        if (!VarSetOps::IsMember(comp, mask, varDsc->lvVarIndex))
            continue;

        if (VarSetOps::IsMember(comp, life, varDsc->lvVarIndex))
            printf("V%02u ", lclNum);
    }
}

#endif

/*****************************************************************************/
#ifdef DEBUG
/*****************************************************************************
 *
 *  Debugging helpers - display variables liveness info.
 */

void dispFPvarsInBBlist(BasicBlock* beg, BasicBlock* end, VARSET_TP mask, Compiler* comp)
{
    do
    {
        printf("BB%02u: ", beg->bbNum);

        printf(" in  = [ ");
        dispLifeSet(comp, mask, beg->bbLiveIn);
        printf("] ,");

        printf(" out = [ ");
        dispLifeSet(comp, mask, beg->bbLiveOut);
        printf("]");

        if (beg->bbFlags & BBF_VISITED)
            printf(" inner=%u", beg->bbFPinVars);

        printf("\n");

        beg = beg->bbNext;
        if (!beg)
            return;
    } while (beg != end);
}

#if FEATURE_STACK_FP_X87
void Compiler::raDispFPlifeInfo()
{
    BasicBlock* block;

    for (block = fgFirstBB; block; block = block->bbNext)
    {
        GenTreePtr stmt;

        printf("BB%02u: in  = [ ", block->bbNum);
        dispLifeSet(this, optAllFloatVars, block->bbLiveIn);
        printf("]\n\n");

        VARSET_TP life(VarSetOps::MakeCopy(this, block->bbLiveIn));
        for (stmt = block->bbTreeList; stmt; stmt = stmt->gtNext)
        {
            GenTreePtr tree;

            noway_assert(stmt->gtOper == GT_STMT);

            for (tree = stmt->gtStmt.gtStmtList; tree; tree = tree->gtNext)
            {
                VarSetOps::AssignNoCopy(this, life, fgUpdateLiveSet(life, tree));

                dispLifeSet(this, optAllFloatVars, life);
                printf("   ");
                gtDispTree(tree, 0, NULL, true);
            }

            printf("\n");
        }

        printf("BB%02u: out = [ ", block->bbNum);
        dispLifeSet(this, optAllFloatVars, block->bbLiveOut);
        printf("]\n\n");
    }
}
#endif // FEATURE_STACK_FP_X87
/*****************************************************************************/
#endif // DEBUG
/*****************************************************************************/

/*****************************************************************************/

void Compiler::raSetRegVarOrder(
    var_types regType, regNumber* customVarOrder, unsigned* customVarOrderSize, regMaskTP prefReg, regMaskTP avoidReg)
{
    unsigned         normalVarOrderSize;
    const regNumber* normalVarOrder = raGetRegVarOrder(regType, &normalVarOrderSize);
    unsigned         index;
    unsigned         listIndex = 0;
    regMaskTP        usedReg   = avoidReg;

    noway_assert(*customVarOrderSize >= normalVarOrderSize);

    if (prefReg)
    {
        /* First place the preferred registers at the start of customVarOrder */

        regMaskTP regBit;
        regNumber regNum;

        for (index = 0; index < normalVarOrderSize; index++)
        {
            regNum = normalVarOrder[index];
            regBit = genRegMask(regNum);

            if (usedReg & regBit)
                continue;

            if (prefReg & regBit)
            {
                usedReg |= regBit;
                noway_assert(listIndex < normalVarOrderSize);
                customVarOrder[listIndex++] = regNum;
                prefReg -= regBit;
                if (prefReg == 0)
                    break;
            }
        }

#if CPU_HAS_BYTE_REGS
        /* Then if byteable registers are preferred place them */

        if (prefReg & RBM_BYTE_REG_FLAG)
        {
            for (index = 0; index < normalVarOrderSize; index++)
            {
                regNum = normalVarOrder[index];
                regBit = genRegMask(regNum);

                if (usedReg & regBit)
                    continue;

                if (RBM_BYTE_REGS & regBit)
                {
                    usedReg |= regBit;
                    noway_assert(listIndex < normalVarOrderSize);
                    customVarOrder[listIndex++] = regNum;
                }
            }
        }

#endif // CPU_HAS_BYTE_REGS
    }

    /* Now place all the non-preferred registers */

    for (index = 0; index < normalVarOrderSize; index++)
    {
        regNumber regNum = normalVarOrder[index];
        regMaskTP regBit = genRegMask(regNum);

        if (usedReg & regBit)
            continue;

        usedReg |= regBit;
        noway_assert(listIndex < normalVarOrderSize);
        customVarOrder[listIndex++] = regNum;
    }

    if (avoidReg)
    {
        /* Now place the "avoid" registers */

        for (index = 0; index < normalVarOrderSize; index++)
        {
            regNumber regNum = normalVarOrder[index];
            regMaskTP regBit = genRegMask(regNum);

            if (avoidReg & regBit)
            {
                noway_assert(listIndex < normalVarOrderSize);
                customVarOrder[listIndex++] = regNum;
                avoidReg -= regBit;
                if (avoidReg == 0)
                    break;
            }
        }
    }

    *customVarOrderSize = listIndex;
    noway_assert(listIndex == normalVarOrderSize);
}

/*****************************************************************************
 *
 *  Setup the raAvoidArgRegMask and rsCalleeRegArgMaskLiveIn
 */

void Compiler::raSetupArgMasks(RegState* regState)
{
    /* Determine the registers holding incoming register arguments */
    /*  and setup raAvoidArgRegMask to the set of registers that we  */
    /*  may want to avoid when enregistering the locals.            */

    regState->rsCalleeRegArgMaskLiveIn = RBM_NONE;
    raAvoidArgRegMask                  = RBM_NONE;

    LclVarDsc* argsEnd = lvaTable + info.compArgsCount;

    for (LclVarDsc* argDsc = lvaTable; argDsc < argsEnd; argDsc++)
    {
        noway_assert(argDsc->lvIsParam);

        // Is it a register argument ?
        if (!argDsc->lvIsRegArg)
            continue;

        // only process args that apply to the current register file
        if ((argDsc->IsFloatRegType() && !info.compIsVarArgs && !opts.compUseSoftFP) != regState->rsIsFloat)
        {
            continue;
        }

        // Is it dead on entry ??
        // In certain cases such as when compJmpOpUsed is true,
        // or when we have a generic type context arg that we must report
        // then the arguments have to be kept alive throughout the prolog.
        // So we have to consider it as live on entry.
        //
        bool keepArgAlive = compJmpOpUsed;
        if ((unsigned(info.compTypeCtxtArg) != BAD_VAR_NUM) && lvaReportParamTypeArg() &&
            ((lvaTable + info.compTypeCtxtArg) == argDsc))
        {
            keepArgAlive = true;
        }

        if (!keepArgAlive && argDsc->lvTracked && !VarSetOps::IsMember(this, fgFirstBB->bbLiveIn, argDsc->lvVarIndex))
        {
            continue;
        }

        // The code to set the regState for each arg is outlined for shared use
        // by linear scan
        regNumber inArgReg = raUpdateRegStateForArg(regState, argDsc);

        // Do we need to try to avoid this incoming arg registers?

        // If it's not tracked, don't do the stuff below.
        if (!argDsc->lvTracked)
            continue;

        // If the incoming arg is used after a call it is live accross
        //  a call and will have to be allocated to a caller saved
        //  register anyway (a very common case).
        //
        // In this case it is pointless to ask that the higher ref count
        //  locals to avoid using the incoming arg register

        unsigned argVarIndex = argDsc->lvVarIndex;

        /* Does the incoming register and the arg variable interfere? */

        if (!VarSetOps::IsMember(this, raLclRegIntf[inArgReg], argVarIndex))
        {
            // No they do not interfere,
            //  so we add inArgReg to raAvoidArgRegMask

            raAvoidArgRegMask |= genRegMask(inArgReg);
        }
#ifdef _TARGET_ARM_
        if (argDsc->lvType == TYP_DOUBLE)
        {
            // Avoid the double register argument pair for register allocation.
            if (!VarSetOps::IsMember(this, raLclRegIntf[inArgReg + 1], argVarIndex))
            {
                raAvoidArgRegMask |= genRegMask(static_cast<regNumber>(inArgReg + 1));
            }
        }
#endif
    }
}

#endif // LEGACY_BACKEND

// The code to set the regState for each arg is outlined for shared use
// by linear scan. (It is not shared for System V AMD64 platform.)
regNumber Compiler::raUpdateRegStateForArg(RegState* regState, LclVarDsc* argDsc)
{
    regNumber inArgReg  = argDsc->lvArgReg;
    regMaskTP inArgMask = genRegMask(inArgReg);

    if (regState->rsIsFloat)
    {
        noway_assert(inArgMask & RBM_FLTARG_REGS);
    }
    else //  regState is for the integer registers
    {
        // This might be the fixed return buffer register argument (on ARM64)
        // We check and allow inArgReg to be theFixedRetBuffReg
        if (hasFixedRetBuffReg() && (inArgReg == theFixedRetBuffReg()))
        {
            // We should have a TYP_BYREF or TYP_I_IMPL arg and not a TYP_STRUCT arg
            noway_assert(argDsc->lvType == TYP_BYREF || argDsc->lvType == TYP_I_IMPL);
            // We should have recorded the variable number for the return buffer arg
            noway_assert(info.compRetBuffArg != BAD_VAR_NUM);
        }
        else // we have a regular arg
        {
            noway_assert(inArgMask & RBM_ARG_REGS);
        }
    }

    regState->rsCalleeRegArgMaskLiveIn |= inArgMask;

#ifdef _TARGET_ARM_
    if (argDsc->lvType == TYP_DOUBLE)
    {
        if (info.compIsVarArgs || opts.compUseSoftFP)
        {
            assert((inArgReg == REG_R0) || (inArgReg == REG_R2));
            assert(!regState->rsIsFloat);
        }
        else
        {
            assert(regState->rsIsFloat);
            assert(emitter::isDoubleReg(inArgReg));
        }
        regState->rsCalleeRegArgMaskLiveIn |= genRegMask((regNumber)(inArgReg + 1));
    }
    else if (argDsc->lvType == TYP_LONG)
    {
        assert((inArgReg == REG_R0) || (inArgReg == REG_R2));
        assert(!regState->rsIsFloat);
        regState->rsCalleeRegArgMaskLiveIn |= genRegMask((regNumber)(inArgReg + 1));
    }
#endif // _TARGET_ARM_

#if FEATURE_MULTIREG_ARGS
    if (argDsc->lvType == TYP_STRUCT)
    {
        if (argDsc->lvIsHfaRegArg())
        {
            assert(regState->rsIsFloat);
            unsigned cSlots = GetHfaCount(argDsc->lvVerTypeInfo.GetClassHandleForValueClass());
            for (unsigned i = 1; i < cSlots; i++)
            {
                assert(inArgReg + i <= LAST_FP_ARGREG);
                regState->rsCalleeRegArgMaskLiveIn |= genRegMask(static_cast<regNumber>(inArgReg + i));
            }
        }
        else
        {
            unsigned cSlots = argDsc->lvSize() / TARGET_POINTER_SIZE;
            for (unsigned i = 1; i < cSlots; i++)
            {
                regNumber nextArgReg = (regNumber)(inArgReg + i);
                if (nextArgReg > REG_ARG_LAST)
                {
                    break;
                }
                assert(regState->rsIsFloat == false);
                regState->rsCalleeRegArgMaskLiveIn |= genRegMask(nextArgReg);
            }
        }
    }
#endif // FEATURE_MULTIREG_ARGS

    return inArgReg;
}

#ifdef LEGACY_BACKEND // We don't use any of the old register allocator functions when LSRA is used instead.

/*****************************************************************************
 *
 *  Assign variables to live in registers, etc.
 */

void Compiler::raAssignVars()
{
#ifdef DEBUG
    if (verbose)
        printf("*************** In raAssignVars()\n");
#endif
    /* We need to keep track of which registers we ever touch */

    codeGen->regSet.rsClearRegsModified();

#if FEATURE_STACK_FP_X87
    // FP register allocation
    raEnregisterVarsStackFP();
    raGenerateFPRefCounts();
#endif

    /* Predict registers used by code generation */
    rpPredictRegUse(); // New reg predictor/allocator

    // Change all unused promoted non-argument struct locals to a non-GC type (in this case TYP_INT)
    // so that the gc tracking logic and lvMustInit logic will ignore them.

    unsigned   lclNum;
    LclVarDsc* varDsc;

    for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
    {
        if (varDsc->lvType != TYP_STRUCT)
            continue;

        if (!varDsc->lvPromoted)
            continue;

        if (varDsc->lvIsParam)
            continue;

        if (varDsc->lvRefCnt > 0)
            continue;

#ifdef DEBUG
        if (verbose)
        {
            printf("Mark unused struct local V%02u\n", lclNum);
        }

        lvaPromotionType promotionType = lvaGetPromotionType(varDsc);

        if (promotionType == PROMOTION_TYPE_DEPENDENT)
        {
            // This should only happen when all its field locals are unused as well.

            for (unsigned varNum = varDsc->lvFieldLclStart; varNum < varDsc->lvFieldLclStart + varDsc->lvFieldCnt;
                 varNum++)
            {
                noway_assert(lvaTable[varNum].lvRefCnt == 0);
            }
        }
        else
        {
            noway_assert(promotionType == PROMOTION_TYPE_INDEPENDENT);
        }

        varDsc->lvUnusedStruct = 1;
#endif

        // Change such struct locals to ints

        varDsc->lvType = TYP_INT; // Bash to a non-gc type.
        noway_assert(!varDsc->lvTracked);
        noway_assert(!varDsc->lvRegister);
        varDsc->lvOnFrame  = false; // Force it not to be onstack.
        varDsc->lvMustInit = false; // Force not to init it.
        varDsc->lvStkOffs  = 0;     // Set it to anything other than BAD_STK_OFFS to make genSetScopeInfo() happy
    }
}

/*****************************************************************************/
/*****************************************************************************/

/*****************************************************************************
 *
 *   Given a regNumber return the correct predictReg enum value
 */

inline static rpPredictReg rpGetPredictForReg(regNumber reg)
{
    return (rpPredictReg)(((int)reg) + ((int)PREDICT_REG_FIRST));
}

/*****************************************************************************
 *
 *   Given a varIndex return the correct predictReg enum value
 */

inline static rpPredictReg rpGetPredictForVarIndex(unsigned varIndex)
{
    return (rpPredictReg)(varIndex + ((int)PREDICT_REG_VAR_T00));
}

/*****************************************************************************
 *
 *   Given a rpPredictReg return the correct varNumber value
 */

inline static unsigned rpGetVarIndexForPredict(rpPredictReg predict)
{
    return (unsigned)predict - (unsigned)PREDICT_REG_VAR_T00;
}

/*****************************************************************************
 *
 *   Given a rpPredictReg return true if it specifies a Txx register
 */

inline static bool rpHasVarIndexForPredict(rpPredictReg predict)
{
    if ((predict >= PREDICT_REG_VAR_T00) && (predict <= PREDICT_REG_VAR_MAX))
        return true;
    else
        return false;
}

/*****************************************************************************
 *
 *   Given a regmask return the correct predictReg enum value
 */

static rpPredictReg rpGetPredictForMask(regMaskTP regmask)
{
    rpPredictReg result = PREDICT_NONE;
    if (regmask != 0) /* Check if regmask has zero bits set */
    {
        if (((regmask - 1) & regmask) == 0) /* Check if regmask has one bit set */
        {
            DWORD reg = 0;
            assert(FitsIn<DWORD>(regmask));
            BitScanForward(&reg, (DWORD)regmask);
            return rpGetPredictForReg((regNumber)reg);
        }

#if defined(_TARGET_ARM_)
        /* It has multiple bits set */
        else if (regmask == (RBM_R0 | RBM_R1))
        {
            result = PREDICT_PAIR_R0R1;
        }
        else if (regmask == (RBM_R2 | RBM_R3))
        {
            result = PREDICT_PAIR_R2R3;
        }
#elif defined(_TARGET_X86_)
        /* It has multiple bits set */
        else if (regmask == (RBM_EAX | RBM_EDX))
        {
            result = PREDICT_PAIR_EAXEDX;
        }
        else if (regmask == (RBM_ECX | RBM_EBX))
        {
            result = PREDICT_PAIR_ECXEBX;
        }
#endif
        else /* It doesn't match anything */
        {
            result = PREDICT_NONE;
            assert(!"unreachable");
            NO_WAY("bad regpair");
        }
    }
    return result;
}

/*****************************************************************************
 *
 *  Record a variable to register(s) interference
 */

bool Compiler::rpRecordRegIntf(regMaskTP regMask, VARSET_VALARG_TP life DEBUGARG(const char* msg))

{
    bool addedIntf = false;

    if (regMask != 0)
    {
        for (regNumber regNum = REG_FIRST; regNum < REG_COUNT; regNum = REG_NEXT(regNum))
        {
            regMaskTP regBit = genRegMask(regNum);

            if (regMask & regBit)
            {
                VARSET_TP newIntf(VarSetOps::Diff(this, life, raLclRegIntf[regNum]));
                if (!VarSetOps::IsEmpty(this, newIntf))
                {
#ifdef DEBUG
                    if (verbose)
                    {
                        VarSetOps::Iter newIntfIter(this, newIntf);
                        unsigned        varNum = 0;
                        while (newIntfIter.NextElem(&varNum))
                        {
                            unsigned   lclNum = lvaTrackedToVarNum[varNum];
                            LclVarDsc* varDsc = &lvaTable[varNum];
#if FEATURE_FP_REGALLOC
                            // Only print the useful interferences
                            // i.e. floating point LclVar interference with floating point registers
                            //         or integer LclVar interference with general purpose registers
                            if (varTypeIsFloating(varDsc->TypeGet()) == genIsValidFloatReg(regNum))
#endif
                            {
                                printf("Record interference between V%02u,T%02u and %s -- %s\n", lclNum, varNum,
                                       getRegName(regNum), msg);
                            }
                        }
                    }
#endif
                    addedIntf = true;
                    VarSetOps::UnionD(this, raLclRegIntf[regNum], newIntf);
                }

                regMask -= regBit;
                if (regMask == 0)
                    break;
            }
        }
    }
    return addedIntf;
}

/*****************************************************************************
 *
 *  Record a new variable to variable(s) interference
 */

bool Compiler::rpRecordVarIntf(unsigned varNum, VARSET_VALARG_TP intfVar DEBUGARG(const char* msg))
{
    noway_assert((varNum >= 0) && (varNum < lvaTrackedCount));
    noway_assert(!VarSetOps::IsEmpty(this, intfVar));

    VARSET_TP oneVar(VarSetOps::MakeEmpty(this));
    VarSetOps::AddElemD(this, oneVar, varNum);

    bool newIntf = fgMarkIntf(intfVar, oneVar);

    if (newIntf)
        rpAddedVarIntf = true;

#ifdef DEBUG
    if (verbose && newIntf)
    {
        for (unsigned oneNum = 0; oneNum < lvaTrackedCount; oneNum++)
        {
            if (VarSetOps::IsMember(this, intfVar, oneNum))
            {
                unsigned lclNum = lvaTrackedToVarNum[varNum];
                unsigned lclOne = lvaTrackedToVarNum[oneNum];
                printf("Record interference between V%02u,T%02u and V%02u,T%02u -- %s\n", lclNum, varNum, lclOne,
                       oneNum, msg);
            }
        }
    }
#endif

    return newIntf;
}

/*****************************************************************************
 *
 *   Determine preferred register mask for a given predictReg value
 */

inline regMaskTP Compiler::rpPredictRegMask(rpPredictReg predictReg, var_types type)
{
    if (rpHasVarIndexForPredict(predictReg))
        predictReg = PREDICT_REG;

    noway_assert((unsigned)predictReg < sizeof(rpPredictMap) / sizeof(rpPredictMap[0]));
    noway_assert(rpPredictMap[predictReg] != RBM_ILLEGAL);

    regMaskTP regAvailForType = rpPredictMap[predictReg];
    if (varTypeIsFloating(type))
    {
        regAvailForType &= RBM_ALLFLOAT;
    }
    else
    {
        regAvailForType &= RBM_ALLINT;
    }
#ifdef _TARGET_ARM_
    if (type == TYP_DOUBLE)
    {
        if ((predictReg >= PREDICT_REG_F0) && (predictReg <= PREDICT_REG_F31))
        {
            // Fix 388433 ARM JitStress WP7
            if ((regAvailForType & RBM_DBL_REGS) != 0)
            {
                regAvailForType |= (regAvailForType << 1);
            }
            else
            {
                regAvailForType = RBM_NONE;
            }
        }
    }
#endif
    return regAvailForType;
}

/*****************************************************************************
 *
 *  Predict register choice for a type.
 *
 *  Adds the predicted registers to rsModifiedRegsMask.
 */
regMaskTP Compiler::rpPredictRegPick(var_types type, rpPredictReg predictReg, regMaskTP lockedRegs)
{
    regMaskTP preferReg = rpPredictRegMask(predictReg, type);
    regNumber regNum;
    regMaskTP regBits;

    // Add any reserved register to the lockedRegs
    lockedRegs |= codeGen->regSet.rsMaskResvd;

    /* Clear out the lockedRegs from preferReg */
    preferReg &= ~lockedRegs;

    if (rpAsgVarNum != -1)
    {
        noway_assert((rpAsgVarNum >= 0) && (rpAsgVarNum < (int)lclMAX_TRACKED));

        /* Don't pick the register used by rpAsgVarNum either */
        LclVarDsc* tgtVar = lvaTable + lvaTrackedToVarNum[rpAsgVarNum];
        noway_assert(tgtVar->lvRegNum != REG_STK);

        preferReg &= ~genRegMask(tgtVar->lvRegNum);
    }

    switch (type)
    {
        case TYP_BOOL:
        case TYP_BYTE:
        case TYP_UBYTE:
        case TYP_SHORT:
        case TYP_CHAR:
        case TYP_INT:
        case TYP_UINT:
        case TYP_REF:
        case TYP_BYREF:
#ifdef _TARGET_AMD64_
        case TYP_LONG:
#endif // _TARGET_AMD64_

            // expand preferReg to all non-locked registers if no bits set
            preferReg = codeGen->regSet.rsUseIfZero(preferReg & RBM_ALLINT, RBM_ALLINT & ~lockedRegs);

            if (preferReg == 0) // no bits set?
            {
                // Add one predefined spill choice register if no bits set.
                // (The jit will introduce one spill temp)
                preferReg |= RBM_SPILL_CHOICE;
                rpPredictSpillCnt++;

#ifdef DEBUG
                if (verbose)
                    printf("Predict one spill temp\n");
#endif
            }

            if (preferReg != 0)
            {
                /* Iterate the registers in the order specified by rpRegTmpOrder */

                for (unsigned index = 0; index < REG_TMP_ORDER_COUNT; index++)
                {
                    regNum  = rpRegTmpOrder[index];
                    regBits = genRegMask(regNum);

                    if ((preferReg & regBits) == regBits)
                    {
                        goto RET;
                    }
                }
            }
            /* Otherwise we have allocated all registers, so do nothing */
            break;

#ifndef _TARGET_AMD64_
        case TYP_LONG:

            if ((preferReg == 0) ||                   // no bits set?
                ((preferReg & (preferReg - 1)) == 0)) // or only one bit set?
            {
                // expand preferReg to all non-locked registers
                preferReg = RBM_ALLINT & ~lockedRegs;
            }

            if (preferReg == 0) // no bits set?
            {
                // Add EAX:EDX to the registers
                // (The jit will introduce two spill temps)
                preferReg = RBM_PAIR_TMP;
                rpPredictSpillCnt += 2;
#ifdef DEBUG
                if (verbose)
                    printf("Predict two spill temps\n");
#endif
            }
            else if ((preferReg & (preferReg - 1)) == 0) // only one bit set?
            {
                if ((preferReg & RBM_PAIR_TMP_LO) == 0)
                {
                    // Add EAX to the registers
                    // (The jit will introduce one spill temp)
                    preferReg |= RBM_PAIR_TMP_LO;
                }
                else
                {
                    // Add EDX to the registers
                    // (The jit will introduce one spill temp)
                    preferReg |= RBM_PAIR_TMP_HI;
                }
                rpPredictSpillCnt++;
#ifdef DEBUG
                if (verbose)
                    printf("Predict one spill temp\n");
#endif
            }

            regPairNo regPair;
            regPair = codeGen->regSet.rsFindRegPairNo(preferReg);
            if (regPair != REG_PAIR_NONE)
            {
                regBits = genRegPairMask(regPair);
                goto RET;
            }

            /* Otherwise we have allocated all registers, so do nothing */
            break;
#endif // _TARGET_AMD64_

#ifdef _TARGET_ARM_
        case TYP_STRUCT:
#endif

        case TYP_FLOAT:
        case TYP_DOUBLE:

#if FEATURE_FP_REGALLOC
            regMaskTP restrictMask;
            restrictMask = (raConfigRestrictMaskFP() | RBM_FLT_CALLEE_TRASH);
            assert((restrictMask & RBM_SPILL_CHOICE_FLT) == RBM_SPILL_CHOICE_FLT);

            // expand preferReg to all available non-locked registers if no bits set
            preferReg = codeGen->regSet.rsUseIfZero(preferReg & restrictMask, restrictMask & ~lockedRegs);
            regMaskTP preferDouble;
            preferDouble = preferReg & (preferReg >> 1);

            if ((preferReg == 0) // no bits set?
#ifdef _TARGET_ARM_
                || ((type == TYP_DOUBLE) &&
                    ((preferReg & (preferReg >> 1)) == 0)) // or two consecutive bits set for TYP_DOUBLE
#endif
                )
            {
                // Add one predefined spill choice register if no bits set.
                // (The jit will introduce one spill temp)
                preferReg |= RBM_SPILL_CHOICE_FLT;
                rpPredictSpillCnt++;

#ifdef DEBUG
                if (verbose)
                    printf("Predict one spill temp (float)\n");
#endif
            }

            assert(preferReg != 0);

            /* Iterate the registers in the order specified by raRegFltTmpOrder */

            for (unsigned index = 0; index < REG_FLT_TMP_ORDER_COUNT; index++)
            {
                regNum  = raRegFltTmpOrder[index];
                regBits = genRegMask(regNum);

                if (varTypeIsFloating(type))
                {
#ifdef _TARGET_ARM_
                    if (type == TYP_DOUBLE)
                    {
                        if ((regBits & RBM_DBL_REGS) == 0)
                        {
                            continue; // We must restrict the set to the double registers
                        }
                        else
                        {
                            // TYP_DOUBLE use two consecutive registers
                            regBits |= genRegMask(REG_NEXT(regNum));
                        }
                    }
#endif
                    // See if COMPlus_JitRegisterFP is restricting this FP register
                    //
                    if ((restrictMask & regBits) != regBits)
                        continue;
                }

                if ((preferReg & regBits) == regBits)
                {
                    goto RET;
                }
            }
            /* Otherwise we have allocated all registers, so do nothing */
            break;

#else // !FEATURE_FP_REGALLOC

            return RBM_NONE;

#endif

        default:
            noway_assert(!"unexpected type in reg use prediction");
    }

    /* Abnormal return */
    noway_assert(!"Ran out of registers in rpPredictRegPick");
    return RBM_NONE;

RET:
    /*
     *  If during the first prediction we need to allocate
     *  one of the registers that we used for coloring locals
     *  then flag this by setting rpPredictAssignAgain.
     *  We will have to go back and repredict the registers
     */
    if ((rpPasses == 0) && ((rpPredictAssignMask & regBits) == regBits))
        rpPredictAssignAgain = true;

    // Add a register interference to each of the last use variables
    if (!VarSetOps::IsEmpty(this, rpLastUseVars) || !VarSetOps::IsEmpty(this, rpUseInPlace))
    {
        VARSET_TP lastUse(VarSetOps::MakeEmpty(this));
        VarSetOps::Assign(this, lastUse, rpLastUseVars);
        VARSET_TP inPlaceUse(VarSetOps::MakeEmpty(this));
        VarSetOps::Assign(this, inPlaceUse, rpUseInPlace);
        // While we still have any lastUse or inPlaceUse bits
        VARSET_TP useUnion(VarSetOps::Union(this, lastUse, inPlaceUse));

        VARSET_TP       varAsSet(VarSetOps::MakeEmpty(this));
        VarSetOps::Iter iter(this, useUnion);
        unsigned        varNum = 0;
        while (iter.NextElem(&varNum))
        {
            // We'll need this for one of the calls...
            VarSetOps::OldStyleClearD(this, varAsSet);
            VarSetOps::AddElemD(this, varAsSet, varNum);

            // If this varBit and lastUse?
            if (VarSetOps::IsMember(this, lastUse, varNum))
            {
                // Record a register to variable interference
                rpRecordRegIntf(regBits, varAsSet DEBUGARG("last use RegPick"));
            }

            // If this varBit and inPlaceUse?
            if (VarSetOps::IsMember(this, inPlaceUse, varNum))
            {
                // Record a register to variable interference
                rpRecordRegIntf(regBits, varAsSet DEBUGARG("used in place RegPick"));
            }
        }
    }
    codeGen->regSet.rsSetRegsModified(regBits);

    return regBits;
}

/*****************************************************************************
 *
 *  Predict integer register use for generating an address mode for a tree,
 *  by setting tree->gtUsedRegs to all registers used by this tree and its
 *  children.
 *    tree       - is the child of a GT_IND node
 *    type       - the type of the GT_IND node (floating point/integer)
 *    lockedRegs - are the registers which are currently held by
 *                 a previously evaluated node.
 *    rsvdRegs   - registers which should not be allocated because they will
 *                 be needed to evaluate a node in the future
 *               - Also if rsvdRegs has the RBM_LASTUSE bit set then
 *                 the rpLastUseVars set should be saved and restored
 *                 so that we don't add any new variables to rpLastUseVars
 *    lenCSE     - is non-NULL only when we have a lenCSE expression
 *
 *  Return the scratch registers to be held by this tree. (one or two registers
 *  to form an address expression)
 */

regMaskTP Compiler::rpPredictAddressMode(
    GenTreePtr tree, var_types type, regMaskTP lockedRegs, regMaskTP rsvdRegs, GenTreePtr lenCSE)
{
    GenTreePtr op1;
    GenTreePtr op2;
    GenTreePtr opTemp;
    genTreeOps oper = tree->OperGet();
    regMaskTP  op1Mask;
    regMaskTP  op2Mask;
    regMaskTP  regMask;
    ssize_t    sh;
    ssize_t    cns = 0;
    bool       rev;
    bool       hasTwoAddConst     = false;
    bool       restoreLastUseVars = false;
    VARSET_TP  oldLastUseVars(VarSetOps::MakeEmpty(this));

    /* do we need to save and restore the rpLastUseVars set ? */
    if ((rsvdRegs & RBM_LASTUSE) && (lenCSE == NULL))
    {
        restoreLastUseVars = true;
        VarSetOps::Assign(this, oldLastUseVars, rpLastUseVars);
    }
    rsvdRegs &= ~RBM_LASTUSE;

    /* if not an add, then just force it to a register */

    if (oper != GT_ADD)
    {
        if (oper == GT_ARR_ELEM)
        {
            regMask = rpPredictTreeRegUse(tree, PREDICT_NONE, lockedRegs, rsvdRegs);
            goto DONE;
        }
        else
        {
            goto NO_ADDR_EXPR;
        }
    }

    op1 = tree->gtOp.gtOp1;
    op2 = tree->gtOp.gtOp2;
    rev = ((tree->gtFlags & GTF_REVERSE_OPS) != 0);

    /* look for (x + y) + icon address mode */

    if (op2->OperGet() == GT_CNS_INT)
    {
        cns = op2->gtIntCon.gtIconVal;

        /* if not an add, then just force op1 into a register */
        if (op1->OperGet() != GT_ADD)
            goto ONE_ADDR_EXPR;

        hasTwoAddConst = true;

        /* Record the 'rev' flag, reverse evaluation order */
        rev = ((op1->gtFlags & GTF_REVERSE_OPS) != 0);

        op2 = op1->gtOp.gtOp2;
        op1 = op1->gtOp.gtOp1; // Overwrite op1 last!!
    }

    /* Check for CNS_INT or LSH of CNS_INT in op2 slot */

    sh = 0;
    if (op2->OperGet() == GT_LSH)
    {
        if (op2->gtOp.gtOp2->OperGet() == GT_CNS_INT)
        {
            sh     = op2->gtOp.gtOp2->gtIntCon.gtIconVal;
            opTemp = op2->gtOp.gtOp1;
        }
        else
        {
            opTemp = NULL;
        }
    }
    else
    {
        opTemp = op2;
    }

    if (opTemp != NULL)
    {
        if (opTemp->OperGet() == GT_NOP)
        {
            opTemp = opTemp->gtOp.gtOp1;
        }

        // Is this a const operand?
        if (opTemp->OperGet() == GT_CNS_INT)
        {
            // Compute the new cns value that Codegen will end up using
            cns += (opTemp->gtIntCon.gtIconVal << sh);

            goto ONE_ADDR_EXPR;
        }
    }

    /* Check for LSH in op1 slot */

    if (op1->OperGet() != GT_LSH)
        goto TWO_ADDR_EXPR;

    opTemp = op1->gtOp.gtOp2;

    if (opTemp->OperGet() != GT_CNS_INT)
        goto TWO_ADDR_EXPR;

    sh = opTemp->gtIntCon.gtIconVal;

    /* Check for LSH of 0, special case */
    if (sh == 0)
        goto TWO_ADDR_EXPR;

#if defined(_TARGET_XARCH_)

    /* Check for LSH of 1 2 or 3 */
    if (sh > 3)
        goto TWO_ADDR_EXPR;

#elif defined(_TARGET_ARM_)

    /* Check for LSH of 1 to 30 */
    if (sh > 30)
        goto TWO_ADDR_EXPR;

#else

    goto TWO_ADDR_EXPR;

#endif

    /* Matched a leftShift by 'sh' subtree, move op1 down */
    op1 = op1->gtOp.gtOp1;

TWO_ADDR_EXPR:

    /* Now we have to evaluate op1 and op2 into registers */

    /* Evaluate op1 and op2 in the correct order */
    if (rev)
    {
        op2Mask = rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs, rsvdRegs | op1->gtRsvdRegs);
        op1Mask = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs | op2Mask, rsvdRegs);
    }
    else
    {
        op1Mask = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
        op2Mask = rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs | op1Mask, rsvdRegs);
    }

    /*  If op1 and op2 must be spilled and reloaded then
     *  op1 and op2 might be reloaded into the same register
     *  This can only happen when all the registers are lockedRegs
     */
    if ((op1Mask == op2Mask) && (op1Mask != 0))
    {
        /* We'll need to grab a different register for op2 */
        op2Mask = rpPredictRegPick(TYP_INT, PREDICT_REG, op1Mask);
    }

#ifdef _TARGET_ARM_
    // On the ARM we need a scratch register to evaluate the shifted operand for trees that have this form
    //      [op2 + op1<<sh + cns]
    // when op1 is an enregistered variable, thus the op1Mask is RBM_NONE
    //
    if (hasTwoAddConst && (sh != 0) && (op1Mask == RBM_NONE))
    {
        op1Mask |= rpPredictRegPick(TYP_INT, PREDICT_REG, (lockedRegs | op1Mask | op2Mask));
    }

    //
    // On the ARM we will need at least one scratch register for trees that have this form:
    //     [op1 + op2 + cns] or  [op1 + op2<<sh + cns]
    // or for a float/double or long when we have both op1 and op2
    // or when we have an 'cns' that is too large for the ld/st instruction
    //
    if (hasTwoAddConst || varTypeIsFloating(type) || (type == TYP_LONG) || !codeGen->validDispForLdSt(cns, type))
    {
        op2Mask |= rpPredictRegPick(TYP_INT, PREDICT_REG, (lockedRegs | op1Mask | op2Mask));
    }

    //
    // If we create a CSE that immediately dies then we may need to add an additional register interference
    // so we don't color the CSE into R3
    //
    if (!rev && (op1Mask != RBM_NONE) && (op2->OperGet() == GT_COMMA))
    {
        opTemp = op2->gtOp.gtOp2;
        if (opTemp->OperGet() == GT_LCL_VAR)
        {
            unsigned   varNum = opTemp->gtLclVar.gtLclNum;
            LclVarDsc* varDsc = &lvaTable[varNum];

            if (varDsc->lvTracked && !VarSetOps::IsMember(this, compCurLife, varDsc->lvVarIndex))
            {
                rpRecordRegIntf(RBM_TMP_0,
                                VarSetOps::MakeSingleton(this, varDsc->lvVarIndex) DEBUGARG("dead CSE (gt_ind)"));
            }
        }
    }
#endif

    regMask          = (op1Mask | op2Mask);
    tree->gtUsedRegs = (regMaskSmall)regMask;
    goto DONE;

ONE_ADDR_EXPR:

    /* now we have to evaluate op1 into a register */

    op1Mask = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, rsvdRegs);
    op2Mask = RBM_NONE;

#ifdef _TARGET_ARM_
    //
    // On the ARM we will need another scratch register when we have an 'cns' that is too large for the ld/st
    // instruction
    //
    if (!codeGen->validDispForLdSt(cns, type))
    {
        op2Mask |= rpPredictRegPick(TYP_INT, PREDICT_REG, (lockedRegs | op1Mask | op2Mask));
    }
#endif

    regMask          = (op1Mask | op2Mask);
    tree->gtUsedRegs = (regMaskSmall)regMask;
    goto DONE;

NO_ADDR_EXPR:

#if !CPU_LOAD_STORE_ARCH
    if (oper == GT_CNS_INT)
    {
        /* Indirect of a constant does not require a register */
        regMask = RBM_NONE;
    }
    else
#endif
    {
        /* now we have to evaluate tree into a register */
        regMask = rpPredictTreeRegUse(tree, PREDICT_REG, lockedRegs, rsvdRegs);
    }

DONE:
    regMaskTP regUse = tree->gtUsedRegs;

    if (!VarSetOps::IsEmpty(this, compCurLife))
    {
        // Add interference between the current set of life variables and
        //  the set of temporary registers need to evaluate the sub tree
        if (regUse)
        {
            rpRecordRegIntf(regUse, compCurLife DEBUGARG("tmp use (gt_ind)"));
        }
    }

    /* Do we need to resore the oldLastUseVars value */
    if (restoreLastUseVars)
    {
        /*
         *  If we used a GT_ASG targeted register then we need to add
         *  a variable interference between any new last use variables
         *  and the GT_ASG targeted register
         */
        if (!VarSetOps::Equal(this, rpLastUseVars, oldLastUseVars) && rpAsgVarNum != -1)
        {
            rpRecordVarIntf(rpAsgVarNum,
                            VarSetOps::Diff(this, rpLastUseVars, oldLastUseVars) DEBUGARG("asgn conflict (gt_ind)"));
        }
        VarSetOps::Assign(this, rpLastUseVars, oldLastUseVars);
    }

    return regMask;
}

/*****************************************************************************
 *
 *
 */

void Compiler::rpPredictRefAssign(unsigned lclNum)
{
    LclVarDsc* varDsc = lvaTable + lclNum;

    varDsc->lvRefAssign = 1;

#if NOGC_WRITE_BARRIERS
#ifdef DEBUG
    if (verbose)
    {
        if (!VarSetOps::IsMember(this, raLclRegIntf[REG_EDX], varDsc->lvVarIndex))
            printf("Record interference between V%02u,T%02u and REG WRITE BARRIER -- ref assign\n", lclNum,
                   varDsc->lvVarIndex);
    }
#endif

    /* Make sure that write barrier pointer variables never land in EDX */
    VarSetOps::AddElemD(this, raLclRegIntf[REG_EDX], varDsc->lvVarIndex);
#endif // NOGC_WRITE_BARRIERS
}

/*****************************************************************************
 *
 * Predict the internal temp physical register usage for a block assignment tree,
 * by setting tree->gtUsedRegs.
 * Records the internal temp physical register usage for this tree.
 * Returns a mask of interfering registers for this tree.
 *
 * Each of the switch labels in this function updates regMask and assigns tree->gtUsedRegs
 * to the set of scratch registers needed when evaluating the tree.
 * Generally tree->gtUsedRegs and the return value retMask are the same, except when the
 * parameter "lockedRegs" conflicts with the computed tree->gtUsedRegs, in which case we
 * predict additional internal temp physical registers to spill into.
 *
 *    tree       - is the child of a GT_IND node
 *    predictReg - what type of register does the tree need
 *    lockedRegs - are the registers which are currently held by a previously evaluated node.
 *                 Don't modify lockedRegs as it is used at the end to compute a spill mask.
 *    rsvdRegs   - registers which should not be allocated because they will
 *                 be needed to evaluate a node in the future
 *               - Also, if rsvdRegs has the RBM_LASTUSE bit set then
 *                 the rpLastUseVars set should be saved and restored
 *                 so that we don't add any new variables to rpLastUseVars.
 */
regMaskTP Compiler::rpPredictBlkAsgRegUse(GenTreePtr   tree,
                                          rpPredictReg predictReg,
                                          regMaskTP    lockedRegs,
                                          regMaskTP    rsvdRegs)
{
    regMaskTP regMask         = RBM_NONE;
    regMaskTP interferingRegs = RBM_NONE;

    bool        hasGCpointer  = false;
    bool        dstIsOnStack  = false;
    bool        useMemHelper  = false;
    bool        useBarriers   = false;
    GenTreeBlk* dst           = tree->gtGetOp1()->AsBlk();
    GenTreePtr  dstAddr       = dst->Addr();
    GenTreePtr  srcAddrOrFill = tree->gtGetOp2IfPresent();

    size_t blkSize = dst->gtBlkSize;

    hasGCpointer = (dst->HasGCPtr());

    bool isCopyBlk = tree->OperIsCopyBlkOp();
    bool isCopyObj = isCopyBlk && hasGCpointer;
    bool isInitBlk = tree->OperIsInitBlkOp();

    if (isCopyBlk)
    {
        assert(srcAddrOrFill->OperIsIndir());
        srcAddrOrFill = srcAddrOrFill->AsIndir()->Addr();
    }
    else
    {
        // For initBlk, we don't need to worry about the GC pointers.
        hasGCpointer = false;
    }

    if (blkSize != 0)
    {
        if (isCopyObj)
        {
            dstIsOnStack = (dstAddr->gtOper == GT_ADDR && (dstAddr->gtFlags & GTF_ADDR_ONSTACK));
        }

        if (isInitBlk)
        {
            if (srcAddrOrFill->OperGet() != GT_CNS_INT)
            {
                useMemHelper = true;
            }
        }
    }
    else
    {
        useMemHelper = true;
    }

    if (hasGCpointer && !dstIsOnStack)
    {
        useBarriers = true;
    }

#ifdef _TARGET_ARM_
    //
    // On ARM For COPYBLK & INITBLK we have special treatment for constant lengths.
    //
    if (!useMemHelper && !useBarriers)
    {
        bool     useLoop        = false;
        unsigned fullStoreCount = blkSize / TARGET_POINTER_SIZE;

        // A mask to use to force the predictor to choose low registers (to reduce code size)
        regMaskTP avoidReg = (RBM_R12 | RBM_LR);

        // Allow the src and dst to be used in place, unless we use a loop, in which
        // case we will need scratch registers as we will be writing to them.
        rpPredictReg srcAndDstPredict = PREDICT_REG;

        // Will we be using a loop to implement this INITBLK/COPYBLK?
        if ((isCopyBlk && (fullStoreCount >= 8)) || (isInitBlk && (fullStoreCount >= 16)))
        {
            useLoop          = true;
            avoidReg         = RBM_NONE;
            srcAndDstPredict = PREDICT_SCRATCH_REG;
        }

        if (tree->gtFlags & GTF_REVERSE_OPS)
        {
            regMask |= rpPredictTreeRegUse(srcAddrOrFill, srcAndDstPredict, lockedRegs,
                                           dstAddr->gtRsvdRegs | avoidReg | RBM_LASTUSE);
            regMask |= rpPredictTreeRegUse(dstAddr, srcAndDstPredict, lockedRegs | regMask, avoidReg);
        }
        else
        {
            regMask |= rpPredictTreeRegUse(dstAddr, srcAndDstPredict, lockedRegs,
                                           srcAddrOrFill->gtRsvdRegs | avoidReg | RBM_LASTUSE);
            regMask |= rpPredictTreeRegUse(srcAddrOrFill, srcAndDstPredict, lockedRegs | regMask, avoidReg);
        }

        // We need at least one scratch register for a copyBlk
        if (isCopyBlk)
        {
            // Pick a low register to reduce the code size
            regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regMask | avoidReg);
        }

        if (useLoop)
        {
            if (isCopyBlk)
            {
                // We need a second temp register for a copyBlk (our code gen is load two/store two)
                // Pick another low register to reduce the code size
                regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regMask | avoidReg);
            }

            // We need a loop index register
            regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regMask);
        }

        tree->gtUsedRegs = dstAddr->gtUsedRegs | srcAddrOrFill->gtUsedRegs | (regMaskSmall)regMask;

        return interferingRegs;
    }
#endif
    // What order should the Dest, Val/Src, and Size be calculated
    GenTreePtr opsPtr[3];
    regMaskTP  regsPtr[3];

#if defined(_TARGET_XARCH_)
    fgOrderBlockOps(tree, RBM_EDI, (isInitBlk) ? RBM_EAX : RBM_ESI, RBM_ECX, opsPtr, regsPtr);

    // We're going to use these, might as well make them available now

    codeGen->regSet.rsSetRegsModified(RBM_EDI | RBM_ECX);
    if (isCopyBlk)
        codeGen->regSet.rsSetRegsModified(RBM_ESI);

#elif defined(_TARGET_ARM_)

    if (useMemHelper)
    {
        // For all other cases that involve non-constants, we just call memcpy/memset
        // JIT helpers
        fgOrderBlockOps(tree, RBM_ARG_0, RBM_ARG_1, RBM_ARG_2, opsPtr, regsPtr);
        interferingRegs |= RBM_CALLEE_TRASH;
#ifdef DEBUG
        if (verbose)
            printf("Adding interference with RBM_CALLEE_TRASH for memcpy/memset\n");
#endif
    }
    else // useBarriers
    {
        assert(useBarriers);
        assert(isCopyBlk);

        fgOrderBlockOps(tree, RBM_ARG_0, RBM_ARG_1, REG_TMP_1, opsPtr, regsPtr);

        // For this case Codegen will call the CORINFO_HELP_ASSIGN_BYREF helper
        interferingRegs |= RBM_CALLEE_TRASH_NOGC;
#ifdef DEBUG
        if (verbose)
            printf("Adding interference with RBM_CALLEE_TRASH_NOGC for Byref WriteBarrier\n");
#endif
    }
#else // !_TARGET_X86_ && !_TARGET_ARM_
#error "Non-ARM or x86 _TARGET_ in RegPredict for INITBLK/COPYBLK"
#endif // !_TARGET_X86_ && !_TARGET_ARM_
    regMaskTP opsPtr2RsvdRegs = opsPtr[2] == nullptr ? RBM_NONE : opsPtr[2]->gtRsvdRegs;
    regMask |= rpPredictTreeRegUse(opsPtr[0], rpGetPredictForMask(regsPtr[0]), lockedRegs,
                                   opsPtr[1]->gtRsvdRegs | opsPtr2RsvdRegs | RBM_LASTUSE);
    regMask |= regsPtr[0];
    opsPtr[0]->gtUsedRegs |= regsPtr[0];
    rpRecordRegIntf(regsPtr[0], compCurLife DEBUGARG("movsd dest"));

    regMask |= rpPredictTreeRegUse(opsPtr[1], rpGetPredictForMask(regsPtr[1]), lockedRegs | regMask,
                                   opsPtr2RsvdRegs | RBM_LASTUSE);
    regMask |= regsPtr[1];
    opsPtr[1]->gtUsedRegs |= regsPtr[1];
    rpRecordRegIntf(regsPtr[1], compCurLife DEBUGARG("movsd src"));

    regMaskSmall opsPtr2UsedRegs = (regMaskSmall)regsPtr[2];
    if (opsPtr[2] == nullptr)
    {
        // If we have no "size" node, we will predict that regsPtr[2] will be used for the size.
        // Note that it is quite possible that no register is required, but this preserves
        // former behavior.
        regMask |= rpPredictRegPick(TYP_INT, rpGetPredictForMask(regsPtr[2]), lockedRegs | regMask);
        rpRecordRegIntf(regsPtr[2], compCurLife DEBUGARG("tmp use"));
    }
    else
    {
        regMask |= rpPredictTreeRegUse(opsPtr[2], rpGetPredictForMask(regsPtr[2]), lockedRegs | regMask, RBM_NONE);
        opsPtr[2]->gtUsedRegs |= opsPtr2UsedRegs;
    }
    regMask |= opsPtr2UsedRegs;

    tree->gtUsedRegs = opsPtr[0]->gtUsedRegs | opsPtr[1]->gtUsedRegs | opsPtr2UsedRegs | (regMaskSmall)regMask;
    return interferingRegs;
}

/*****************************************************************************
 *
 * Predict the internal temp physical register usage for a tree by setting tree->gtUsedRegs.
 * Returns a regMask with the internal temp physical register usage for this tree.
 *
 * Each of the switch labels in this function updates regMask and assigns tree->gtUsedRegs
 * to the set of scratch registers needed when evaluating the tree.
 * Generally tree->gtUsedRegs and the return value retMask are the same, except when the
 * parameter "lockedRegs" conflicts with the computed tree->gtUsedRegs, in which case we
 * predict additional internal temp physical registers to spill into.
 *
 *    tree       - is the child of a GT_IND node
 *    predictReg - what type of register does the tree need
 *    lockedRegs - are the registers which are currently held by a previously evaluated node.
 *                 Don't modify lockedRegs as it is used at the end to compute a spill mask.
 *    rsvdRegs   - registers which should not be allocated because they will
 *                 be needed to evaluate a node in the future
 *               - Also, if rsvdRegs has the RBM_LASTUSE bit set then
 *                 the rpLastUseVars set should be saved and restored
 *                 so that we don't add any new variables to rpLastUseVars.
 */

#pragma warning(disable : 4701)

#ifdef _PREFAST_
#pragma warning(push)
#pragma warning(disable : 21000) // Suppress PREFast warning about overly large function
#endif
regMaskTP Compiler::rpPredictTreeRegUse(GenTreePtr   tree,
                                        rpPredictReg predictReg,
                                        regMaskTP    lockedRegs,
                                        regMaskTP    rsvdRegs)
{
    regMaskTP    regMask = DUMMY_INIT(RBM_ILLEGAL);
    regMaskTP    op2Mask;
    regMaskTP    tmpMask;
    rpPredictReg op1PredictReg;
    rpPredictReg op2PredictReg;
    LclVarDsc*   varDsc = NULL;
    VARSET_TP    oldLastUseVars(VarSetOps::UninitVal());

    VARSET_TP varBits(VarSetOps::UninitVal());
    VARSET_TP lastUseVarBits(VarSetOps::MakeEmpty(this));

    bool      restoreLastUseVars = false;
    regMaskTP interferingRegs    = RBM_NONE;

#ifdef DEBUG
    // if (verbose) printf("rpPredictTreeRegUse() [%08x]\n", tree);
    noway_assert(tree);
    noway_assert(((RBM_ILLEGAL & RBM_ALLINT) == 0));
    noway_assert(RBM_ILLEGAL);
    noway_assert((lockedRegs & RBM_ILLEGAL) == 0);
    /* impossible values, to make sure that we set them */
    tree->gtUsedRegs = RBM_ILLEGAL;
#endif

    /* Figure out what kind of a node we have */

    genTreeOps oper = tree->OperGet();
    var_types  type = tree->TypeGet();
    unsigned   kind = tree->OperKind();

    // In the comma case, we care about whether this is "effectively" ADDR(IND(...))
    genTreeOps effectiveOper = tree->gtEffectiveVal()->OperGet();
    if ((predictReg == PREDICT_ADDR) && (effectiveOper != GT_IND))
        predictReg = PREDICT_NONE;
    else if (rpHasVarIndexForPredict(predictReg))
    {
        // The only place where predictReg is set to a var is in the PURE
        // assignment case where varIndex is the var being assigned to.
        // We need to check whether the variable is used between here and
        // its redefinition.
        unsigned varIndex = rpGetVarIndexForPredict(predictReg);
        unsigned lclNum   = lvaTrackedToVarNum[varIndex];
        bool     found    = false;
        for (GenTreePtr nextTree = tree->gtNext; nextTree != NULL && !found; nextTree = nextTree->gtNext)
        {
            if (nextTree->gtOper == GT_LCL_VAR && nextTree->gtLclVarCommon.gtLclNum == lclNum)
            {
                // Is this the pure assignment?
                if ((nextTree->gtFlags & GTF_VAR_DEF) == 0)
                {
                    predictReg = PREDICT_SCRATCH_REG;
                }
                found = true;
                break;
            }
        }
        assert(found);
    }

    if (rsvdRegs & RBM_LASTUSE)
    {
        restoreLastUseVars = true;
        VarSetOps::Assign(this, oldLastUseVars, rpLastUseVars);
        rsvdRegs &= ~RBM_LASTUSE;
    }

    /* Is this a constant or leaf node? */

    if (kind & (GTK_CONST | GTK_LEAF))
    {
        bool      lastUse   = false;
        regMaskTP enregMask = RBM_NONE;

        switch (oper)
        {
#ifdef _TARGET_ARM_
            case GT_CNS_DBL:
                // Codegen for floating point constants on the ARM is currently
                // movw/movt    rT1, <lo32 bits>
                // movw/movt    rT2, <hi32 bits>
                //  vmov.i2d    dT0, rT1,rT2
                //
                // For TYP_FLOAT one integer register is required
                //
                // These integer register(s) immediately die
                tmpMask = rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | rsvdRegs);
                if (type == TYP_DOUBLE)
                {
                    // For TYP_DOUBLE a second integer register is required
                    //
                    tmpMask |= rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | rsvdRegs | tmpMask);
                }

                // We also need a floating point register that we keep
                //
                if (predictReg == PREDICT_NONE)
                    predictReg = PREDICT_SCRATCH_REG;

                regMask          = rpPredictRegPick(type, predictReg, lockedRegs | rsvdRegs);
                tree->gtUsedRegs = regMask | tmpMask;
                goto RETURN_CHECK;
#endif

            case GT_CNS_INT:
            case GT_CNS_LNG:

                if (rpHasVarIndexForPredict(predictReg))
                {
                    unsigned tgtIndex = rpGetVarIndexForPredict(predictReg);
                    rpAsgVarNum       = tgtIndex;

                    // We don't need any register as we plan on writing to the rpAsgVarNum register
                    predictReg = PREDICT_NONE;

                    LclVarDsc* tgtVar   = lvaTable + lvaTrackedToVarNum[tgtIndex];
                    tgtVar->lvDependReg = true;

                    if (type == TYP_LONG)
                    {
                        assert(oper == GT_CNS_LNG);

                        if (tgtVar->lvOtherReg == REG_STK)
                        {
                            // Well we do need one register for a partially enregistered
                            type       = TYP_INT;
                            predictReg = PREDICT_SCRATCH_REG;
                        }
                    }
                }
                else
                {
#if !CPU_LOAD_STORE_ARCH
                    /* If the constant is a handle then it will need to have a relocation
                       applied to it.  It will need to be loaded into a register.
                       But never throw away an existing hint.
                       */
                    if (opts.compReloc && tree->IsCnsIntOrI() && tree->IsIconHandle())
#endif
                    {
                        if (predictReg == PREDICT_NONE)
                            predictReg = PREDICT_SCRATCH_REG;
                    }
                }
                break;

            case GT_NO_OP:
                break;

            case GT_CLS_VAR:
                if ((predictReg == PREDICT_NONE) && (genActualType(type) == TYP_INT) &&
                    (genTypeSize(type) < sizeof(int)))
                {
                    predictReg = PREDICT_SCRATCH_REG;
                }
#ifdef _TARGET_ARM_
                // Unaligned loads/stores for floating point values must first be loaded into integer register(s)
                //
                if ((tree->gtFlags & GTF_IND_UNALIGNED) && varTypeIsFloating(type))
                {
                    // These integer register(s) immediately die
                    tmpMask = rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | rsvdRegs);
                    // Two integer registers are required for a TYP_DOUBLE
                    if (type == TYP_DOUBLE)
                        tmpMask |= rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | rsvdRegs | tmpMask);
                }
                // We need a temp register in some cases of loads/stores to a class var
                if (predictReg == PREDICT_NONE)
                {
                    predictReg = PREDICT_SCRATCH_REG;
                }
#endif
                if (rpHasVarIndexForPredict(predictReg))
                {
                    unsigned tgtIndex = rpGetVarIndexForPredict(predictReg);
                    rpAsgVarNum       = tgtIndex;

                    // We don't need any register as we plan on writing to the rpAsgVarNum register
                    predictReg = PREDICT_NONE;

                    LclVarDsc* tgtVar   = lvaTable + lvaTrackedToVarNum[tgtIndex];
                    tgtVar->lvDependReg = true;

                    if (type == TYP_LONG)
                    {
                        if (tgtVar->lvOtherReg == REG_STK)
                        {
                            // Well we do need one register for a partially enregistered
                            type       = TYP_INT;
                            predictReg = PREDICT_SCRATCH_REG;
                        }
                    }
                }
                break;

            case GT_LCL_FLD:
#ifdef _TARGET_ARM_
                // Check for a misalignment on a Floating Point field
                //
                if (varTypeIsFloating(type))
                {
                    if ((tree->gtLclFld.gtLclOffs % emitTypeSize(tree->TypeGet())) != 0)
                    {
                        // These integer register(s) immediately die
                        tmpMask = rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | rsvdRegs);
                        // Two integer registers are required for a TYP_DOUBLE
                        if (type == TYP_DOUBLE)
                            tmpMask |= rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | rsvdRegs | tmpMask);
                    }
                }
#endif
                __fallthrough;

            case GT_LCL_VAR:
            case GT_REG_VAR:

                varDsc = lvaTable + tree->gtLclVarCommon.gtLclNum;

                VarSetOps::Assign(this, varBits, fgGetVarBits(tree));
                compUpdateLifeVar</*ForCodeGen*/ false>(tree, &lastUseVarBits);
                lastUse = !VarSetOps::IsEmpty(this, lastUseVarBits);

#if FEATURE_STACK_FP_X87
                // If it's a floating point var, there's nothing to do
                if (varTypeIsFloating(type))
                {
                    tree->gtUsedRegs = RBM_NONE;
                    regMask          = RBM_NONE;
                    goto RETURN_CHECK;
                }
#endif

                // If the variable is already a register variable, no need to go further.
                if (oper == GT_REG_VAR)
                    break;

                /* Apply the type of predictReg to the LCL_VAR */

                if (predictReg == PREDICT_REG)
                {
                PREDICT_REG_COMMON:
                    if (varDsc->lvRegNum == REG_STK)
                        break;

                    goto GRAB_COUNT;
                }
                else if (predictReg == PREDICT_SCRATCH_REG)
                {
                    noway_assert(predictReg == PREDICT_SCRATCH_REG);

                    /* Is this the last use of a local var?   */
                    if (lastUse)
                    {
                        if (VarSetOps::IsEmptyIntersection(this, rpUseInPlace, lastUseVarBits))
                            goto PREDICT_REG_COMMON;
                    }
                }
                else if (rpHasVarIndexForPredict(predictReg))
                {
                    /* Get the tracked local variable that has an lvVarIndex of tgtIndex1 */
                    {
                        unsigned   tgtIndex1 = rpGetVarIndexForPredict(predictReg);
                        LclVarDsc* tgtVar    = lvaTable + lvaTrackedToVarNum[tgtIndex1];
                        VarSetOps::MakeSingleton(this, tgtIndex1);

                        noway_assert(tgtVar->lvVarIndex == tgtIndex1);
                        noway_assert(tgtVar->lvRegNum != REG_STK); /* Must have been enregistered */
#ifndef _TARGET_AMD64_
                        // On amd64 we have the occasional spec-allowed implicit conversion from TYP_I_IMPL to TYP_INT
                        // so this assert is meaningless
                        noway_assert((type != TYP_LONG) || (tgtVar->TypeGet() == TYP_LONG));
#endif // !_TARGET_AMD64_

                        if (varDsc->lvTracked)
                        {
                            unsigned srcIndex;
                            srcIndex = varDsc->lvVarIndex;

                            // If this register has it's last use here then we will prefer
                            // to color to the same register as tgtVar.
                            if (lastUse)
                            {
                                /*
                                 *  Add an entry in the lvaVarPref graph to indicate
                                 *  that it would be worthwhile to color these two variables
                                 *  into the same physical register.
                                 *  This will help us avoid having an extra copy instruction
                                 */
                                VarSetOps::AddElemD(this, lvaVarPref[srcIndex], tgtIndex1);
                                VarSetOps::AddElemD(this, lvaVarPref[tgtIndex1], srcIndex);
                            }

                            // Add a variable interference from srcIndex to each of the last use variables
                            if (!VarSetOps::IsEmpty(this, rpLastUseVars))
                            {
                                rpRecordVarIntf(srcIndex, rpLastUseVars DEBUGARG("src reg conflict"));
                            }
                        }
                        rpAsgVarNum = tgtIndex1;

                        /* We will rely on the target enregistered variable from the GT_ASG */
                        varDsc = tgtVar;
                    }
                GRAB_COUNT:
                    unsigned grabCount;
                    grabCount = 0;

                    if (genIsValidFloatReg(varDsc->lvRegNum))
                    {
                        enregMask = genRegMaskFloat(varDsc->lvRegNum, varDsc->TypeGet());
                    }
                    else
                    {
                        enregMask = genRegMask(varDsc->lvRegNum);
                    }

#ifdef _TARGET_ARM_
                    if ((type == TYP_DOUBLE) && (varDsc->TypeGet() == TYP_FLOAT))
                    {
                        // We need to compute the intermediate value using a TYP_DOUBLE
                        // but we storing the result in a TYP_SINGLE enregistered variable
                        //
                        grabCount++;
                    }
                    else
#endif
                    {
                        /* We can't trust a prediction of rsvdRegs or lockedRegs sets */
                        if (enregMask & (rsvdRegs | lockedRegs))
                        {
                            grabCount++;
                        }
#ifndef _TARGET_64BIT_
                        if (type == TYP_LONG)
                        {
                            if (varDsc->lvOtherReg != REG_STK)
                            {
                                tmpMask = genRegMask(varDsc->lvOtherReg);
                                enregMask |= tmpMask;

                                /* We can't trust a prediction of rsvdRegs or lockedRegs sets */
                                if (tmpMask & (rsvdRegs | lockedRegs))
                                    grabCount++;
                            }
                            else // lvOtherReg == REG_STK
                            {
                                grabCount++;
                            }
                        }
#endif // _TARGET_64BIT_
                    }

                    varDsc->lvDependReg = true;

                    if (grabCount == 0)
                    {
                        /* Does not need a register */
                        predictReg = PREDICT_NONE;
                        // noway_assert(!VarSetOps::IsEmpty(this, varBits));
                        VarSetOps::UnionD(this, rpUseInPlace, varBits);
                    }
                    else // (grabCount > 0)
                    {
#ifndef _TARGET_64BIT_
                        /* For TYP_LONG and we only need one register then change the type to TYP_INT */
                        if ((type == TYP_LONG) && (grabCount == 1))
                        {
                            /* We will need to pick one register */
                            type = TYP_INT;
                            // noway_assert(!VarSetOps::IsEmpty(this, varBits));
                            VarSetOps::UnionD(this, rpUseInPlace, varBits);
                        }
                        noway_assert((type == TYP_DOUBLE) ||
                                     (grabCount == (genTypeSize(genActualType(type)) / REGSIZE_BYTES)));
#else  // !_TARGET_64BIT_
                        noway_assert(grabCount == 1);
#endif // !_TARGET_64BIT_
                    }
                }
                else if (type == TYP_STRUCT)
                {
#ifdef _TARGET_ARM_
                    // TODO-ARM-Bug?: Passing structs in registers on ARM hits an assert here when
                    //        predictReg is PREDICT_REG_R0 to PREDICT_REG_R3
                    //        As a workaround we just bash it to PREDICT_NONE here
                    //
                    if (predictReg != PREDICT_NONE)
                        predictReg = PREDICT_NONE;
#endif
                    // Currently predictReg is saying that we will not need any scratch registers
                    noway_assert(predictReg == PREDICT_NONE);

                    /* We may need to sign or zero extend a small type when pushing a struct */
                    if (varDsc->lvPromoted && !varDsc->lvAddrExposed)
                    {
                        for (unsigned varNum = varDsc->lvFieldLclStart;
                             varNum < varDsc->lvFieldLclStart + varDsc->lvFieldCnt; varNum++)
                        {
                            LclVarDsc* fldVar = lvaTable + varNum;

                            if (fldVar->lvStackAligned())
                            {
                                // When we are stack aligned Codegen will just use
                                // a push instruction and thus doesn't need any register
                                // since we can push both a register or a stack frame location
                                continue;
                            }

                            if (varTypeIsByte(fldVar->TypeGet()))
                            {
                                // We will need to reserve one byteable register,
                                //
                                type       = TYP_BYTE;
                                predictReg = PREDICT_SCRATCH_REG;
#if CPU_HAS_BYTE_REGS
                                // It is best to enregister this fldVar in a byteable register
                                //
                                fldVar->addPrefReg(RBM_BYTE_REG_FLAG, this);
#endif
                            }
                            else if (varTypeIsShort(fldVar->TypeGet()))
                            {
                                bool isEnregistered = fldVar->lvTracked && (fldVar->lvRegNum != REG_STK);
                                // If fldVar is not enregistered then we will need a scratch register
                                //
                                if (!isEnregistered)
                                {
                                    // We will need either an int register or a byte register
                                    // If we are not requesting a byte register we will request an int register
                                    //
                                    if (type != TYP_BYTE)
                                        type   = TYP_INT;
                                    predictReg = PREDICT_SCRATCH_REG;
                                }
                            }
                        }
                    }
                }
                else
                {
                    regMaskTP preferReg = rpPredictRegMask(predictReg, type);
                    if (preferReg != 0)
                    {
                        if ((genTypeStSz(type) == 1) || (genCountBits(preferReg) <= genTypeStSz(type)))
                        {
                            varDsc->addPrefReg(preferReg, this);
                        }
                    }
                }
                break; /* end of case GT_LCL_VAR */

            case GT_JMP:
                tree->gtUsedRegs = RBM_NONE;
                regMask          = RBM_NONE;

#if defined(_TARGET_ARM_) && defined(PROFILING_SUPPORTED)
                // Mark the registers required to emit a tailcall profiler callback
                if (compIsProfilerHookNeeded())
                {
                    tree->gtUsedRegs |= RBM_PROFILER_JMP_USED;
                }
#endif
                goto RETURN_CHECK;

            default:
                break;
        } /* end of switch (oper) */

        /* If we don't need to evaluate to register, regmask is the empty set */
        /* Otherwise we grab a temp for the local variable                    */

        if (predictReg == PREDICT_NONE)
            regMask = RBM_NONE;
        else
        {
            regMask = rpPredictRegPick(type, predictReg, lockedRegs | rsvdRegs | enregMask);

            if ((oper == GT_LCL_VAR) && (tree->TypeGet() == TYP_STRUCT))
            {
                /* We need to sign or zero extend a small type when pushing a struct */
                noway_assert((type == TYP_INT) || (type == TYP_BYTE));

                varDsc = lvaTable + tree->gtLclVarCommon.gtLclNum;
                noway_assert(varDsc->lvPromoted && !varDsc->lvAddrExposed);

                for (unsigned varNum = varDsc->lvFieldLclStart; varNum < varDsc->lvFieldLclStart + varDsc->lvFieldCnt;
                     varNum++)
                {
                    LclVarDsc* fldVar = lvaTable + varNum;
                    if (fldVar->lvTracked)
                    {
                        VARSET_TP fldBit(VarSetOps::MakeSingleton(this, fldVar->lvVarIndex));
                        rpRecordRegIntf(regMask, fldBit DEBUGARG(
                                                     "need scratch register when pushing a small field of a struct"));
                    }
                }
            }
        }

        /* Update the set of lastUse variables that we encountered so far */
        if (lastUse)
        {
            VarSetOps::UnionD(this, rpLastUseVars, lastUseVarBits);
            VARSET_TP varAsSet(VarSetOps::MakeCopy(this, lastUseVarBits));

            /*
             *  Add interference from any previously locked temps into this last use variable.
             */
            if (lockedRegs)
            {
                rpRecordRegIntf(lockedRegs, varAsSet DEBUGARG("last use Predict lockedRegs"));
            }
            /*
             *  Add interference from any reserved temps into this last use variable.
             */
            if (rsvdRegs)
            {
                rpRecordRegIntf(rsvdRegs, varAsSet DEBUGARG("last use Predict rsvdRegs"));
            }
            /*
             *  For partially enregistered longs add an interference with the
             *  register return by rpPredictRegPick
             */
            if ((type == TYP_INT) && (tree->TypeGet() == TYP_LONG))
            {
                rpRecordRegIntf(regMask, varAsSet DEBUGARG("last use with partial enreg"));
            }
        }

        tree->gtUsedRegs = (regMaskSmall)regMask;
        goto RETURN_CHECK;
    }

    /* Is it a 'simple' unary/binary operator? */

    if (kind & GTK_SMPOP)
    {
        GenTreePtr op1 = tree->gtOp.gtOp1;
        GenTreePtr op2 = tree->gtGetOp2IfPresent();

        GenTreePtr opsPtr[3];
        regMaskTP  regsPtr[3];

        VARSET_TP startAsgUseInPlaceVars(VarSetOps::UninitVal());

        switch (oper)
        {
            case GT_ASG:

                /* Is the value being assigned into a LCL_VAR? */
                if (op1->gtOper == GT_LCL_VAR)
                {
                    varDsc = lvaTable + op1->gtLclVarCommon.gtLclNum;

                    /* Are we assigning a LCL_VAR the result of a call? */
                    if (op2->gtOper == GT_CALL)
                    {
                        /* Set a preferred register for the LCL_VAR */
                        if (isRegPairType(varDsc->TypeGet()))
                            varDsc->addPrefReg(RBM_LNGRET, this);
                        else if (!varTypeIsFloating(varDsc->TypeGet()))
                            varDsc->addPrefReg(RBM_INTRET, this);
#ifdef _TARGET_AMD64_
                        else
                            varDsc->addPrefReg(RBM_FLOATRET, this);
#endif
                        /*
                         *  When assigning the result of a call we don't
                         *  bother trying to target the right side of the
                         *  assignment, since we have a fixed calling convention.
                         */
                    }
                    else if (varDsc->lvTracked)
                    {
                        // We interfere with uses in place
                        if (!VarSetOps::IsEmpty(this, rpUseInPlace))
                        {
                            rpRecordVarIntf(varDsc->lvVarIndex, rpUseInPlace DEBUGARG("Assign UseInPlace conflict"));
                        }

                        // Did we predict that this local will be fully enregistered?
                        // and the assignment type is the same as the expression type?
                        // and it is dead on the right side of the assignment?
                        // and we current have no other rpAsgVarNum active?
                        //
                        if ((varDsc->lvRegNum != REG_STK) && ((type != TYP_LONG) || (varDsc->lvOtherReg != REG_STK)) &&
                            (type == op2->TypeGet()) && (op1->gtFlags & GTF_VAR_DEF) && (rpAsgVarNum == -1))
                        {
                            //
                            //  Yes, we should try to target the right side (op2) of this
                            //  assignment into the (enregistered) tracked variable.
                            //

                            op1PredictReg = PREDICT_NONE; /* really PREDICT_REG, but we've already done the check */
                            op2PredictReg = rpGetPredictForVarIndex(varDsc->lvVarIndex);

                            // Remember that this is a new use in place

                            // We've added "new UseInPlace"; remove from the global set.
                            VarSetOps::RemoveElemD(this, rpUseInPlace, varDsc->lvVarIndex);

                            //  Note that later when we walk down to the leaf node for op2
                            //  if we decide to actually use the register for the 'varDsc'
                            //  to enregister the operand, the we will set rpAsgVarNum to
                            //  varDsc->lvVarIndex, by extracting this value using
                            //  rpGetVarIndexForPredict()
                            //
                            //  Also we reset rpAsgVarNum back to -1 after we have finished
                            //  predicting the current GT_ASG node
                            //
                            goto ASG_COMMON;
                        }
                    }
                }
                else if (tree->OperIsBlkOp())
                {
                    interferingRegs |= rpPredictBlkAsgRegUse(tree, predictReg, lockedRegs, rsvdRegs);
                    regMask = 0;
                    goto RETURN_CHECK;
                }
                __fallthrough;

            case GT_CHS:

            case GT_ASG_OR:
            case GT_ASG_XOR:
            case GT_ASG_AND:
            case GT_ASG_SUB:
            case GT_ASG_ADD:
            case GT_ASG_MUL:
            case GT_ASG_DIV:
            case GT_ASG_UDIV:

                /* We can't use "reg <op>= addr" for TYP_LONG or if op2 is a short type */
                if ((type != TYP_LONG) && !varTypeIsSmall(op2->gtType))
                {
                    /* Is the value being assigned into an enregistered LCL_VAR? */
                    /* For debug code we only allow a simple op2 to be assigned */
                    if ((op1->gtOper == GT_LCL_VAR) && (!opts.compDbgCode || rpCanAsgOperWithoutReg(op2, false)))
                    {
                        varDsc = lvaTable + op1->gtLclVarCommon.gtLclNum;
                        /* Did we predict that this local will be enregistered? */
                        if (varDsc->lvRegNum != REG_STK)
                        {
                            /* Yes, we can use "reg <op>= addr" */

                            op1PredictReg = PREDICT_NONE; /* really PREDICT_REG, but we've already done the check */
                            op2PredictReg = PREDICT_NONE;

                            goto ASG_COMMON;
                        }
                    }
                }

#if CPU_LOAD_STORE_ARCH
                if (oper != GT_ASG)
                {
                    op1PredictReg = PREDICT_REG;
                    op2PredictReg = PREDICT_REG;
                }
                else
#endif
                {
                    /*
                     *  Otherwise, initialize the normal forcing of operands:
                     *   "addr <op>= reg"
                     */
                    op1PredictReg = PREDICT_ADDR;
                    op2PredictReg = PREDICT_REG;
                }

            ASG_COMMON:

#if !CPU_LOAD_STORE_ARCH
                if (op2PredictReg != PREDICT_NONE)
                {
                    /* Is the value being assigned a simple one? */
                    if (rpCanAsgOperWithoutReg(op2, false))
                        op2PredictReg = PREDICT_NONE;
                }
#endif

                bool simpleAssignment;
                simpleAssignment = false;

                if ((oper == GT_ASG) && (op1->gtOper == GT_LCL_VAR))
                {
                    // Add a variable interference from the assign target
                    // to each of the last use variables
                    if (!VarSetOps::IsEmpty(this, rpLastUseVars))
                    {
                        varDsc = lvaTable + op1->gtLclVarCommon.gtLclNum;

                        if (varDsc->lvTracked)
                        {
                            unsigned varIndex = varDsc->lvVarIndex;

                            rpRecordVarIntf(varIndex, rpLastUseVars DEBUGARG("Assign conflict"));
                        }
                    }

                    /*  Record whether this tree is a simple assignment to a local */

                    simpleAssignment = ((type != TYP_LONG) || !opts.compDbgCode);
                }

                bool requireByteReg;
                requireByteReg = false;

#if CPU_HAS_BYTE_REGS
                /* Byte-assignments need the byte registers, unless op1 is an enregistered local */

                if (varTypeIsByte(type) &&
                    ((op1->gtOper != GT_LCL_VAR) || (lvaTable[op1->gtLclVarCommon.gtLclNum].lvRegNum == REG_STK)))

                {
                    // Byte-assignments typically need a byte register
                    requireByteReg = true;

                    if (op1->gtOper == GT_LCL_VAR)
                    {
                        varDsc = lvaTable + op1->gtLclVar.gtLclNum;

                        // Did we predict that this local will be enregistered?
                        if (varDsc->lvTracked && (varDsc->lvRegNum != REG_STK) && (oper != GT_CHS))
                        {
                            // We don't require a byte register when op1 is an enregistered local */
                            requireByteReg = false;
                        }

                        // Is op1 part of an Assign-Op or is the RHS a simple memory indirection?
                        if ((oper != GT_ASG) || (op2->gtOper == GT_IND) || (op2->gtOper == GT_CLS_VAR))
                        {
                            // We should try to put op1 in an byte register
                            varDsc->addPrefReg(RBM_BYTE_REG_FLAG, this);
                        }
                    }
                }
#endif

                VarSetOps::Assign(this, startAsgUseInPlaceVars, rpUseInPlace);

                bool isWriteBarrierAsgNode;
                isWriteBarrierAsgNode = codeGen->gcInfo.gcIsWriteBarrierAsgNode(tree);
#ifdef DEBUG
                GCInfo::WriteBarrierForm wbf;
                if (isWriteBarrierAsgNode)
                    wbf = codeGen->gcInfo.gcIsWriteBarrierCandidate(tree->gtOp.gtOp1, tree->gtOp.gtOp2);
                else
                    wbf = GCInfo::WBF_NoBarrier;
#endif // DEBUG

                regMaskTP wbaLockedRegs;
                wbaLockedRegs = lockedRegs;
                if (isWriteBarrierAsgNode)
                {
#if defined(_TARGET_X86_) && NOGC_WRITE_BARRIERS
#ifdef DEBUG
                    if (wbf != GCInfo::WBF_NoBarrier_CheckNotHeapInDebug)
                    {
#endif // DEBUG
                        wbaLockedRegs |= RBM_WRITE_BARRIER;
                        op1->gtRsvdRegs |= RBM_WRITE_BARRIER; // This will steer op2 away from REG_WRITE_BARRIER
                        assert(REG_WRITE_BARRIER == REG_EDX);
                        op1PredictReg = PREDICT_REG_EDX;
#ifdef DEBUG
                    }
                    else
#endif // DEBUG
#endif // defined(_TARGET_X86_) && NOGC_WRITE_BARRIERS

#if defined(DEBUG) || !(defined(_TARGET_X86_) && NOGC_WRITE_BARRIERS)
                    {
#ifdef _TARGET_X86_
                        op1PredictReg = PREDICT_REG_ECX;
                        op2PredictReg = PREDICT_REG_EDX;
#elif defined(_TARGET_ARM_)
                        op1PredictReg = PREDICT_REG_R0;
                        op2PredictReg = PREDICT_REG_R1;

                        // This is my best guess as to what the previous code meant by checking "gtRngChkLen() == NULL".
                        if ((op1->OperGet() == GT_IND) && (op1->gtOp.gtOp1->OperGet() != GT_ARR_BOUNDS_CHECK))
                        {
                            op1 = op1->gtOp.gtOp1;
                        }
#else // !_TARGET_X86_ && !_TARGET_ARM_
#error "Non-ARM or x86 _TARGET_ in RegPredict for WriteBarrierAsg"
#endif
                    }
#endif
                }

                /*  Are we supposed to evaluate RHS first? */

                if (tree->gtFlags & GTF_REVERSE_OPS)
                {
                    op2Mask = rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs, rsvdRegs | op1->gtRsvdRegs);

#if CPU_HAS_BYTE_REGS
                    // Should we insure that op2 gets evaluated into a byte register?
                    if (requireByteReg && ((op2Mask & RBM_BYTE_REGS) == 0))
                    {
                        // We need to grab a byte-able register, (i.e. EAX, EDX, ECX, EBX)
                        // and we can't select one that is already reserved (i.e. lockedRegs)
                        //
                        op2Mask |= rpPredictRegPick(type, PREDICT_SCRATCH_REG, (lockedRegs | RBM_NON_BYTE_REGS));
                        op2->gtUsedRegs |= op2Mask;

                        // No longer a simple assignment because we're using extra registers and might
                        // have interference between op1 and op2.  See DevDiv #136681
                        simpleAssignment = false;
                    }
#endif
                    /*
                     *  For a simple assignment we don't want the op2Mask to be
                     *  marked as interferring with the LCL_VAR, since it is likely
                     *  that we will want to enregister the LCL_VAR in exactly
                     *  the register that is used to compute op2
                     */
                    tmpMask = lockedRegs;

                    if (!simpleAssignment)
                        tmpMask |= op2Mask;

                    regMask = rpPredictTreeRegUse(op1, op1PredictReg, tmpMask, RBM_NONE);

                    // Did we relax the register prediction for op1 and op2 above ?
                    // - because we are depending upon op1 being enregistered
                    //
                    if ((op1PredictReg == PREDICT_NONE) &&
                        ((op2PredictReg == PREDICT_NONE) || rpHasVarIndexForPredict(op2PredictReg)))
                    {
                        /* We must be assigning into an enregistered LCL_VAR */
                        noway_assert(op1->gtOper == GT_LCL_VAR);
                        varDsc = lvaTable + op1->gtLclVar.gtLclNum;
                        noway_assert(varDsc->lvRegNum != REG_STK);

                        /* We need to set lvDependReg, in case we lose the enregistration of op1 */
                        varDsc->lvDependReg = true;
                    }
                }
                else
                {
                    // For the case of simpleAssignments op2 should always be evaluated first
                    noway_assert(!simpleAssignment);

                    regMask = rpPredictTreeRegUse(op1, op1PredictReg, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                    if (isWriteBarrierAsgNode)
                    {
                        wbaLockedRegs |= op1->gtUsedRegs;
                    }
                    op2Mask = rpPredictTreeRegUse(op2, op2PredictReg, wbaLockedRegs | regMask, RBM_NONE);

#if CPU_HAS_BYTE_REGS
                    // Should we insure that op2 gets evaluated into a byte register?
                    if (requireByteReg && ((op2Mask & RBM_BYTE_REGS) == 0))
                    {
                        // We need to grab a byte-able register, (i.e. EAX, EDX, ECX, EBX)
                        // and we can't select one that is already reserved (i.e. lockedRegs or regMask)
                        //
                        op2Mask |=
                            rpPredictRegPick(type, PREDICT_SCRATCH_REG, (lockedRegs | regMask | RBM_NON_BYTE_REGS));
                        op2->gtUsedRegs |= op2Mask;
                    }
#endif
                }

                if (rpHasVarIndexForPredict(op2PredictReg))
                {
                    rpAsgVarNum = -1;
                }

                if (isWriteBarrierAsgNode)
                {
#if NOGC_WRITE_BARRIERS
#ifdef DEBUG
                    if (wbf != GCInfo::WBF_NoBarrier_CheckNotHeapInDebug)
                    {
#endif // DEBUG

                        /* Steer computation away from REG_WRITE_BARRIER as the pointer is
                           passed to the write-barrier call in REG_WRITE_BARRIER */

                        regMask = op2Mask;

                        if (op1->gtOper == GT_IND)
                        {
                            GenTreePtr rv1, rv2;
                            unsigned   mul, cns;
                            bool       rev;

                            /* Special handling of indirect assigns for write barrier */

                            bool yes = codeGen->genCreateAddrMode(op1->gtOp.gtOp1, -1, true, RBM_NONE, &rev, &rv1, &rv2,
                                                                  &mul, &cns);

                            /* Check address mode for enregisterable locals */

                            if (yes)
                            {
                                if (rv1 != NULL && rv1->gtOper == GT_LCL_VAR)
                                {
                                    rpPredictRefAssign(rv1->gtLclVarCommon.gtLclNum);
                                }
                                if (rv2 != NULL && rv2->gtOper == GT_LCL_VAR)
                                {
                                    rpPredictRefAssign(rv2->gtLclVarCommon.gtLclNum);
                                }
                            }
                        }

                        if (op2->gtOper == GT_LCL_VAR)
                        {
                            rpPredictRefAssign(op2->gtLclVarCommon.gtLclNum);
                        }

                        // Add a register interference for REG_WRITE_BARRIER to each of the last use variables
                        if (!VarSetOps::IsEmpty(this, rpLastUseVars))
                        {
                            rpRecordRegIntf(RBM_WRITE_BARRIER,
                                            rpLastUseVars DEBUGARG("WriteBarrier and rpLastUseVars conflict"));
                        }
                        tree->gtUsedRegs |= RBM_WRITE_BARRIER;
#ifdef DEBUG
                    }
                    else
#endif // DEBUG
#endif // NOGC_WRITE_BARRIERS

#if defined(DEBUG) || !NOGC_WRITE_BARRIERS
                    {
#ifdef _TARGET_ARM_
#ifdef DEBUG
                        if (verbose)
                            printf("Adding interference with RBM_CALLEE_TRASH_NOGC for NoGC WriteBarrierAsg\n");
#endif
                        //
                        // For the ARM target we have an optimized JIT Helper
                        // that only trashes a subset of the callee saved registers
                        //

                        // NOTE: Adding it to the gtUsedRegs will cause the interference to
                        // be added appropriately

                        // the RBM_CALLEE_TRASH_NOGC set is killed.  We will record this in interferingRegs
                        // instead of gtUsedRegs, because the latter will be modified later, but we need
                        // to remember to add the interference.

                        interferingRegs |= RBM_CALLEE_TRASH_NOGC;

                        op1->gtUsedRegs |= RBM_R0;
                        op2->gtUsedRegs |= RBM_R1;
#else // _TARGET_ARM_

#ifdef DEBUG
                        if (verbose)
                            printf("Adding interference with RBM_CALLEE_TRASH for NoGC WriteBarrierAsg\n");
#endif
                        // We have to call a normal JIT helper to perform the Write Barrier Assignment
                        // It will trash the callee saved registers

                        tree->gtUsedRegs |= RBM_CALLEE_TRASH;
#endif // _TARGET_ARM_
                    }
#endif // defined(DEBUG) || !NOGC_WRITE_BARRIERS
                }

                if (simpleAssignment)
                {
                    /*
                     *  Consider a simple assignment to a local:
                     *
                     *   lcl = expr;
                     *
                     *  Since the "=" node is visited after the variable
                     *  is marked live (assuming it's live after the
                     *  assignment), we don't want to use the register
                     *  use mask of the "=" node but rather that of the
                     *  variable itself.
                     */
                    tree->gtUsedRegs = op1->gtUsedRegs;
                }
                else
                {
                    tree->gtUsedRegs = op1->gtUsedRegs | op2->gtUsedRegs;
                }
                VarSetOps::Assign(this, rpUseInPlace, startAsgUseInPlaceVars);
                goto RETURN_CHECK;

            case GT_ASG_LSH:
            case GT_ASG_RSH:
            case GT_ASG_RSZ:
                /* assigning shift operators */

                noway_assert(type != TYP_LONG);

#if CPU_LOAD_STORE_ARCH
                predictReg = PREDICT_ADDR;
#else
                predictReg = PREDICT_NONE;
#endif

                /* shift count is handled same as ordinary shift */
                goto HANDLE_SHIFT_COUNT;

            case GT_ADDR:
                regMask = rpPredictTreeRegUse(op1, PREDICT_ADDR, lockedRegs, RBM_LASTUSE);

                if ((regMask == RBM_NONE) && (predictReg >= PREDICT_REG))
                {
                    // We need a scratch register for the LEA instruction
                    regMask = rpPredictRegPick(TYP_INT, predictReg, lockedRegs | rsvdRegs);
                }

                tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                goto RETURN_CHECK;

            case GT_CAST:

                /* Cannot cast to VOID */
                noway_assert(type != TYP_VOID);

                /* cast to long is special */
                if (type == TYP_LONG && op1->gtType <= TYP_INT)
                {
                    noway_assert(tree->gtCast.gtCastType == TYP_LONG || tree->gtCast.gtCastType == TYP_ULONG);
#if CPU_LONG_USES_REGPAIR
                    rpPredictReg predictRegHi = PREDICT_SCRATCH_REG;

                    if (rpHasVarIndexForPredict(predictReg))
                    {
                        unsigned tgtIndex = rpGetVarIndexForPredict(predictReg);
                        rpAsgVarNum       = tgtIndex;

                        // We don't need any register as we plan on writing to the rpAsgVarNum register
                        predictReg = PREDICT_NONE;

                        LclVarDsc* tgtVar   = lvaTable + lvaTrackedToVarNum[tgtIndex];
                        tgtVar->lvDependReg = true;

                        if (tgtVar->lvOtherReg != REG_STK)
                        {
                            predictRegHi = PREDICT_NONE;
                        }
                    }
                    else
#endif
                        if (predictReg == PREDICT_NONE)
                    {
                        predictReg = PREDICT_SCRATCH_REG;
                    }
#ifdef _TARGET_ARM_
                    // If we are widening an int into a long using a targeted register pair we
                    // should retarget so that the low part get loaded into the appropriate register
                    else if (predictReg == PREDICT_PAIR_R0R1)
                    {
                        predictReg   = PREDICT_REG_R0;
                        predictRegHi = PREDICT_REG_R1;
                    }
                    else if (predictReg == PREDICT_PAIR_R2R3)
                    {
                        predictReg   = PREDICT_REG_R2;
                        predictRegHi = PREDICT_REG_R3;
                    }
#endif
#ifdef _TARGET_X86_
                    // If we are widening an int into a long using a targeted register pair we
                    // should retarget so that the low part get loaded into the appropriate register
                    else if (predictReg == PREDICT_PAIR_EAXEDX)
                    {
                        predictReg   = PREDICT_REG_EAX;
                        predictRegHi = PREDICT_REG_EDX;
                    }
                    else if (predictReg == PREDICT_PAIR_ECXEBX)
                    {
                        predictReg   = PREDICT_REG_ECX;
                        predictRegHi = PREDICT_REG_EBX;
                    }
#endif

                    regMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);

#if CPU_LONG_USES_REGPAIR
                    if (predictRegHi != PREDICT_NONE)
                    {
                        // Now get one more reg for the upper part
                        regMask |= rpPredictRegPick(TYP_INT, predictRegHi, lockedRegs | rsvdRegs | regMask);
                    }
#endif
                    tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                    goto RETURN_CHECK;
                }

                /* cast from long is special - it frees a register */
                if (type <= TYP_INT // nice.  this presumably is intended to mean "signed int and shorter types"
                    && op1->gtType == TYP_LONG)
                {
                    if ((predictReg == PREDICT_NONE) || rpHasVarIndexForPredict(predictReg))
                        predictReg = PREDICT_REG;

                    regMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);

                    // If we have 2 or more regs, free one of them
                    if (!genMaxOneBit(regMask))
                    {
                        /* Clear the 2nd lowest bit in regMask */
                        /* First set tmpMask to the lowest bit in regMask */
                        tmpMask = genFindLowestBit(regMask);
                        /* Next find the second lowest bit in regMask */
                        tmpMask = genFindLowestBit(regMask & ~tmpMask);
                        /* Clear this bit from regmask */
                        regMask &= ~tmpMask;
                    }
                    tree->gtUsedRegs = op1->gtUsedRegs;
                    goto RETURN_CHECK;
                }

#if CPU_HAS_BYTE_REGS
                /* cast from signed-byte is special - it uses byteable registers */
                if (type == TYP_INT)
                {
                    var_types smallType;

                    if (genTypeSize(tree->gtCast.CastOp()->TypeGet()) < genTypeSize(tree->gtCast.gtCastType))
                        smallType = tree->gtCast.CastOp()->TypeGet();
                    else
                        smallType = tree->gtCast.gtCastType;

                    if (smallType == TYP_BYTE)
                    {
                        regMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);

                        if ((regMask & RBM_BYTE_REGS) == 0)
                            regMask = rpPredictRegPick(type, PREDICT_SCRATCH_REG, RBM_NON_BYTE_REGS);

                        tree->gtUsedRegs = (regMaskSmall)regMask;
                        goto RETURN_CHECK;
                    }
                }
#endif

#if FEATURE_STACK_FP_X87
                /* cast to float/double is special */
                if (varTypeIsFloating(type))
                {
                    switch (op1->TypeGet())
                    {
                        /* uses fild, so don't need to be loaded to reg */
                        case TYP_INT:
                        case TYP_LONG:
                            rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs, rsvdRegs);
                            tree->gtUsedRegs = op1->gtUsedRegs;
                            regMask          = 0;
                            goto RETURN_CHECK;
                        default:
                            break;
                    }
                }

                /* Casting from integral type to floating type is special */
                if (!varTypeIsFloating(type) && varTypeIsFloating(op1->TypeGet()))
                {
                    if (opts.compCanUseSSE2)
                    {
                        // predict for SSE2 based casting
                        if (predictReg <= PREDICT_REG)
                            predictReg = PREDICT_SCRATCH_REG;
                        regMask        = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);

                        // Get one more int reg to hold cast result
                        regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | rsvdRegs | regMask);
                        tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                        goto RETURN_CHECK;
                    }
                }
#endif

#if FEATURE_FP_REGALLOC
                // Are we casting between int to float or float to int
                // Fix 388428 ARM JitStress WP7
                if (varTypeIsFloating(type) != varTypeIsFloating(op1->TypeGet()))
                {
                    // op1 needs to go into a register
                    regMask = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, rsvdRegs);

#ifdef _TARGET_ARM_
                    if (varTypeIsFloating(op1->TypeGet()))
                    {
                        // We also need a fp scratch register for the convert operation
                        regMask |= rpPredictRegPick((genTypeStSz(type) == 1) ? TYP_FLOAT : TYP_DOUBLE,
                                                    PREDICT_SCRATCH_REG, regMask | lockedRegs | rsvdRegs);
                    }
#endif
                    // We also need a register to hold the result
                    regMask |= rpPredictRegPick(type, PREDICT_SCRATCH_REG, regMask | lockedRegs | rsvdRegs);
                    tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                    goto RETURN_CHECK;
                }
#endif

                /* otherwise must load op1 into a register */
                goto GENERIC_UNARY;

            case GT_INTRINSIC:

#ifdef _TARGET_XARCH_
                if (tree->gtIntrinsic.gtIntrinsicId == CORINFO_INTRINSIC_Round && tree->TypeGet() == TYP_INT)
                {
                    // This is a special case to handle the following
                    // optimization: conv.i4(round.d(d)) -> round.i(d)
                    // if flowgraph 3186

                    if (predictReg <= PREDICT_REG)
                        predictReg = PREDICT_SCRATCH_REG;

                    rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);

                    regMask = rpPredictRegPick(TYP_INT, predictReg, lockedRegs | rsvdRegs);

                    tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                    goto RETURN_CHECK;
                }
#endif
                __fallthrough;

            case GT_NEG:
#ifdef _TARGET_ARM_
                if (tree->TypeGet() == TYP_LONG)
                {
                    // On ARM this consumes an extra register for the '0' value
                    if (predictReg <= PREDICT_REG)
                        predictReg = PREDICT_SCRATCH_REG;

                    regMaskTP op1Mask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);

                    regMask = rpPredictRegPick(TYP_INT, predictReg, lockedRegs | op1Mask | rsvdRegs);

                    tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                    goto RETURN_CHECK;
                }
#endif // _TARGET_ARM_

                __fallthrough;

            case GT_NOT:
            // these unary operators will write new values
            // and thus will need a scratch register
            GENERIC_UNARY:
                /* generic unary operators */

                if (predictReg <= PREDICT_REG)
                    predictReg = PREDICT_SCRATCH_REG;

                __fallthrough;

            case GT_NOP:
                // these unary operators do not write new values
                // and thus won't need a scratch register
                CLANG_FORMAT_COMMENT_ANCHOR;

#if OPT_BOOL_OPS
                if (!op1)
                {
                    tree->gtUsedRegs = 0;
                    regMask          = 0;
                    goto RETURN_CHECK;
                }
#endif
                regMask          = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);
                tree->gtUsedRegs = op1->gtUsedRegs;
                goto RETURN_CHECK;

            case GT_IND:
            case GT_NULLCHECK: // At this point, nullcheck is just like an IND...
            {
                bool      intoReg = true;
                VARSET_TP startIndUseInPlaceVars(VarSetOps::MakeCopy(this, rpUseInPlace));

                if (fgIsIndirOfAddrOfLocal(tree) != NULL)
                {
                    compUpdateLifeVar</*ForCodeGen*/ false>(tree);
                }

                if (predictReg == PREDICT_ADDR)
                {
                    intoReg = false;
                }
                else if (predictReg == PREDICT_NONE)
                {
                    if (type != TYP_LONG)
                    {
                        intoReg = false;
                    }
                    else
                    {
                        predictReg = PREDICT_REG;
                    }
                }

                /* forcing to register? */
                if (intoReg && (type != TYP_LONG))
                {
                    rsvdRegs |= RBM_LASTUSE;
                }

                GenTreePtr lenCSE;
                lenCSE = NULL;

                /* check for address mode */
                regMask = rpPredictAddressMode(op1, type, lockedRegs, rsvdRegs, lenCSE);
                tmpMask = RBM_NONE;

#if CPU_LOAD_STORE_ARCH
                // We may need a scratch register for loading a long
                if (type == TYP_LONG)
                {
                    /* This scratch register immediately dies */
                    tmpMask = rpPredictRegPick(TYP_BYREF, PREDICT_REG, op1->gtUsedRegs | lockedRegs | rsvdRegs);
                }
#endif // CPU_LOAD_STORE_ARCH

#ifdef _TARGET_ARM_
                // Unaligned loads/stores for floating point values must first be loaded into integer register(s)
                //
                if ((tree->gtFlags & GTF_IND_UNALIGNED) && varTypeIsFloating(type))
                {
                    /* These integer register(s) immediately die */
                    tmpMask = rpPredictRegPick(TYP_INT, PREDICT_REG, op1->gtUsedRegs | lockedRegs | rsvdRegs);
                    // Two integer registers are required for a TYP_DOUBLE
                    if (type == TYP_DOUBLE)
                        tmpMask |=
                            rpPredictRegPick(TYP_INT, PREDICT_REG, op1->gtUsedRegs | lockedRegs | rsvdRegs | tmpMask);
                }
#endif

                /* forcing to register? */
                if (intoReg)
                {
                    regMaskTP lockedMask = lockedRegs | rsvdRegs;
                    tmpMask |= regMask;

                    // We will compute a new regMask that holds the register(s)
                    // that we will load the indirection into.
                    //
                    CLANG_FORMAT_COMMENT_ANCHOR;

#ifndef _TARGET_64BIT_
                    if (type == TYP_LONG)
                    {
                        // We need to use multiple load instructions here:
                        // For the first register we can not choose
                        // any registers that are being used in place or
                        // any register in the current regMask
                        //
                        regMask = rpPredictRegPick(TYP_INT, predictReg, regMask | lockedMask);

                        // For the second register we can choose a register that was
                        // used in place or any register in the old now overwritten regMask
                        // but not the same register that we picked above in 'regMask'
                        //
                        VarSetOps::Assign(this, rpUseInPlace, startIndUseInPlaceVars);
                        regMask |= rpPredictRegPick(TYP_INT, predictReg, regMask | lockedMask);
                    }
                    else
#endif
                    {
                        // We will use one load instruction here:
                        // The load target register can be a register that was used in place
                        // or one of the register from the orginal regMask.
                        //
                        VarSetOps::Assign(this, rpUseInPlace, startIndUseInPlaceVars);
                        regMask = rpPredictRegPick(type, predictReg, lockedMask);
                    }
                }
                else if (predictReg != PREDICT_ADDR)
                {
                    /* Unless the caller specified PREDICT_ADDR   */
                    /* we don't return the temp registers used    */
                    /* to form the address                        */
                    regMask = RBM_NONE;
                }
            }

                tree->gtUsedRegs = (regMaskSmall)(regMask | tmpMask);

                goto RETURN_CHECK;

            case GT_EQ:
            case GT_NE:
            case GT_LT:
            case GT_LE:
            case GT_GE:
            case GT_GT:

#ifdef _TARGET_X86_
                /* Floating point comparison uses EAX for flags */
                if (varTypeIsFloating(op1->TypeGet()))
                {
                    regMask = RBM_EAX;
                }
                else
#endif
                    if (!(tree->gtFlags & GTF_RELOP_JMP_USED))
                {
                    // Some comparisons are converted to ?:
                    noway_assert(!fgMorphRelopToQmark(op1));

                    if (predictReg <= PREDICT_REG)
                        predictReg = PREDICT_SCRATCH_REG;

                    // The set instructions need a byte register
                    regMask = rpPredictRegPick(TYP_BYTE, predictReg, lockedRegs | rsvdRegs);
                }
                else
                {
                    regMask = RBM_NONE;
#ifdef _TARGET_XARCH_
                    tmpMask = RBM_NONE;
                    // Optimize the compare with a constant cases for xarch
                    if (op1->gtOper == GT_CNS_INT)
                    {
                        if (op2->gtOper == GT_CNS_INT)
                            tmpMask =
                                rpPredictTreeRegUse(op1, PREDICT_SCRATCH_REG, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                        rpPredictTreeRegUse(op2, PREDICT_NONE, lockedRegs | tmpMask, RBM_LASTUSE);
                        tree->gtUsedRegs = op2->gtUsedRegs;
                        goto RETURN_CHECK;
                    }
                    else if (op2->gtOper == GT_CNS_INT)
                    {
                        rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs, rsvdRegs);
                        tree->gtUsedRegs = op1->gtUsedRegs;
                        goto RETURN_CHECK;
                    }
                    else if (op2->gtOper == GT_CNS_LNG)
                    {
                        regMaskTP op1Mask = rpPredictTreeRegUse(op1, PREDICT_ADDR, lockedRegs, rsvdRegs);
#ifdef _TARGET_X86_
                        // We also need one extra register to read values from
                        tmpMask = rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | op1Mask | rsvdRegs);
#endif // _TARGET_X86_
                        tree->gtUsedRegs = (regMaskSmall)tmpMask | op1->gtUsedRegs;
                        goto RETURN_CHECK;
                    }
#endif // _TARGET_XARCH_
                }

                unsigned op1TypeSize;
                unsigned op2TypeSize;

                op1TypeSize = genTypeSize(op1->TypeGet());
                op2TypeSize = genTypeSize(op2->TypeGet());

                op1PredictReg = PREDICT_REG;
                op2PredictReg = PREDICT_REG;

                if (tree->gtFlags & GTF_REVERSE_OPS)
                {
#ifdef _TARGET_XARCH_
                    if (op1TypeSize == sizeof(int))
                        op1PredictReg = PREDICT_NONE;
#endif

                    tmpMask = rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs, rsvdRegs | op1->gtRsvdRegs);
                    rpPredictTreeRegUse(op1, op1PredictReg, lockedRegs | tmpMask, RBM_LASTUSE);
                }
                else
                {
#ifdef _TARGET_XARCH_
                    // For full DWORD compares we can have
                    //
                    //      op1 is an address mode and op2 is a register
                    // or
                    //      op1 is a register and op2 is an address mode
                    //
                    if ((op2TypeSize == sizeof(int)) && (op1TypeSize == op2TypeSize))
                    {
                        if (op2->gtOper == GT_LCL_VAR)
                        {
                            unsigned lclNum = op2->gtLclVar.gtLclNum;
                            varDsc          = lvaTable + lclNum;
                            /* Did we predict that this local will be enregistered? */
                            if (varDsc->lvTracked && (varDsc->lvRegNum != REG_STK))
                            {
                                op1PredictReg = PREDICT_ADDR;
                            }
                        }
                    }
                    // Codegen will generate cmp reg,[mem] for 4 or 8-byte types, but not for 1 or 2 byte types
                    if ((op1PredictReg != PREDICT_ADDR) && (op2TypeSize >= sizeof(int)))
                        op2PredictReg = PREDICT_ADDR;
#endif // _TARGET_XARCH_

                    tmpMask = rpPredictTreeRegUse(op1, op1PredictReg, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
#ifdef _TARGET_ARM_
                    if ((op2->gtOper != GT_CNS_INT) || !codeGen->validImmForAlu(op2->gtIntCon.gtIconVal))
#endif
                    {
                        rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs | tmpMask, RBM_LASTUSE);
                    }
                }

#ifdef _TARGET_XARCH_
                // In some cases in genCondSetFlags(), we need to use a temporary register (via rsPickReg())
                // to generate a sign/zero extension before doing a compare. Save a register for this purpose
                // if one of the registers is small and the types aren't equal.

                if (regMask == RBM_NONE)
                {
                    rpPredictReg op1xPredictReg, op2xPredictReg;
                    GenTreePtr   op1x, op2x;
                    if (tree->gtFlags & GTF_REVERSE_OPS) // TODO: do we really need to handle this case?
                    {
                        op1xPredictReg = op2PredictReg;
                        op2xPredictReg = op1PredictReg;
                        op1x           = op2;
                        op2x           = op1;
                    }
                    else
                    {
                        op1xPredictReg = op1PredictReg;
                        op2xPredictReg = op2PredictReg;
                        op1x           = op1;
                        op2x           = op2;
                    }
                    if ((op1xPredictReg < PREDICT_REG) &&  // op1 doesn't get a register (probably an indir)
                        (op2xPredictReg >= PREDICT_REG) && // op2 gets a register
                        varTypeIsSmall(op1x->TypeGet()))   // op1 is smaller than an int
                    {
                        bool needTmp = false;

                        // If op1x is a byte, and op2x is not a byteable register, we'll need a temp.
                        // We could predict a byteable register for op2x, but what if we don't get it?
                        // So, be conservative and always ask for a temp. There are a couple small CQ losses as a
                        // result.
                        if (varTypeIsByte(op1x->TypeGet()))
                        {
                            needTmp = true;
                        }
                        else
                        {
                            if (op2x->gtOper == GT_LCL_VAR) // this will be a GT_REG_VAR during code generation
                            {
                                if (genActualType(op1x->TypeGet()) != lvaGetActualType(op2x->gtLclVar.gtLclNum))
                                    needTmp = true;
                            }
                            else
                            {
                                if (op1x->TypeGet() != op2x->TypeGet())
                                    needTmp = true;
                            }
                        }
                        if (needTmp)
                        {
                            regMask = rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | rsvdRegs);
                        }
                    }
                }
#endif // _TARGET_XARCH_

                tree->gtUsedRegs = (regMaskSmall)regMask | op1->gtUsedRegs | op2->gtUsedRegs;
                goto RETURN_CHECK;

            case GT_MUL:

#ifndef _TARGET_AMD64_
                if (type == TYP_LONG)
                {
                    assert(tree->gtIsValid64RsltMul());

                    /* Strip out the cast nodes */

                    noway_assert(op1->gtOper == GT_CAST && op2->gtOper == GT_CAST);
                    op1 = op1->gtCast.CastOp();
                    op2 = op2->gtCast.CastOp();
#else
                if (false)
                {
#endif // !_TARGET_AMD64_
                USE_MULT_EAX:

#if defined(_TARGET_X86_)
                    // This will done by a 64-bit imul "imul eax, reg"
                    //   (i.e. EDX:EAX = EAX * reg)

                    /* Are we supposed to evaluate op2 first? */
                    if (tree->gtFlags & GTF_REVERSE_OPS)
                    {
                        rpPredictTreeRegUse(op2, PREDICT_PAIR_TMP_LO, lockedRegs, rsvdRegs | op1->gtRsvdRegs);
                        rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs | RBM_PAIR_TMP_LO, RBM_LASTUSE);
                    }
                    else
                    {
                        rpPredictTreeRegUse(op1, PREDICT_PAIR_TMP_LO, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                        rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs | RBM_PAIR_TMP_LO, RBM_LASTUSE);
                    }

                    /* set gtUsedRegs to EAX, EDX and the registers needed by op1 and op2 */

                    tree->gtUsedRegs = RBM_PAIR_TMP | op1->gtUsedRegs | op2->gtUsedRegs;

                    /* set regMask to the set of held registers */

                    regMask = RBM_PAIR_TMP_LO;

                    if (type == TYP_LONG)
                        regMask |= RBM_PAIR_TMP_HI;

#elif defined(_TARGET_ARM_)
                    // This will done by a 4 operand multiply

                    // Are we supposed to evaluate op2 first?
                    if (tree->gtFlags & GTF_REVERSE_OPS)
                    {
                        rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs, rsvdRegs | op1->gtRsvdRegs);
                        rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, RBM_LASTUSE);
                    }
                    else
                    {
                        rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                        rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs, RBM_LASTUSE);
                    }

                    // set regMask to the set of held registers,
                    //  the two scratch register we need to compute the mul result

                    regMask = rpPredictRegPick(TYP_LONG, PREDICT_SCRATCH_REG, lockedRegs | rsvdRegs);

                    // set gtUsedRegs toregMask and the registers needed by op1 and op2

                    tree->gtUsedRegs = regMask | op1->gtUsedRegs | op2->gtUsedRegs;

#else // !_TARGET_X86_ && !_TARGET_ARM_
#error "Non-ARM or x86 _TARGET_ in RegPredict for 64-bit imul"
#endif

                    goto RETURN_CHECK;
                }
                else
                {
                    /* We use imulEAX for most unsigned multiply operations */
                    if (tree->gtOverflow())
                    {
                        if ((tree->gtFlags & GTF_UNSIGNED) || varTypeIsSmall(tree->TypeGet()))
                        {
                            goto USE_MULT_EAX;
                        }
                    }
                }

                __fallthrough;

            case GT_OR:
            case GT_XOR:
            case GT_AND:

            case GT_SUB:
            case GT_ADD:
                tree->gtUsedRegs = 0;

                if (predictReg <= PREDICT_REG)
                    predictReg = PREDICT_SCRATCH_REG;

            GENERIC_BINARY:

                noway_assert(op2);
                if (tree->gtFlags & GTF_REVERSE_OPS)
                {
                    op1PredictReg = PREDICT_REG;
#if !CPU_LOAD_STORE_ARCH
                    if (genTypeSize(op1->gtType) >= sizeof(int))
                        op1PredictReg = PREDICT_NONE;
#endif
                    regMask = rpPredictTreeRegUse(op2, predictReg, lockedRegs, rsvdRegs | op1->gtRsvdRegs);
                    rpPredictTreeRegUse(op1, op1PredictReg, lockedRegs | regMask, RBM_LASTUSE);
                }
                else
                {
                    op2PredictReg = PREDICT_REG;
#if !CPU_LOAD_STORE_ARCH
                    if (genTypeSize(op2->gtType) >= sizeof(int))
                        op2PredictReg = PREDICT_NONE;
#endif
                    regMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
#ifdef _TARGET_ARM_
                    // For most ALU operations we can generate a single instruction that encodes
                    // a small immediate integer constant value.  (except for multiply)
                    //
                    if ((op2->gtOper == GT_CNS_INT) && (oper != GT_MUL))
                    {
                        ssize_t ival = op2->gtIntCon.gtIconVal;
                        if (codeGen->validImmForAlu(ival))
                        {
                            op2PredictReg = PREDICT_NONE;
                        }
                        else if (codeGen->validImmForAdd(ival, INS_FLAGS_DONT_CARE) &&
                                 ((oper == GT_ADD) || (oper == GT_SUB)))
                        {
                            op2PredictReg = PREDICT_NONE;
                        }
                    }
                    if (op2PredictReg == PREDICT_NONE)
                    {
                        op2->gtUsedRegs = RBM_NONE;
                    }
                    else
#endif
                    {
                        rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs | regMask, RBM_LASTUSE);
                    }
                }
                tree->gtUsedRegs = (regMaskSmall)regMask | op1->gtUsedRegs | op2->gtUsedRegs;

#if CPU_HAS_BYTE_REGS
                /* We have special register requirements for byte operations */

                if (varTypeIsByte(tree->TypeGet()))
                {
                    /* For 8 bit arithmetic, one operands has to be in a
                       byte-addressable register, and the other has to be
                       in a byte-addrble reg or in memory. Assume its in a reg */

                    regMaskTP regByteMask = 0;
                    regMaskTP op1ByteMask = op1->gtUsedRegs;

                    if (!(op1->gtUsedRegs & RBM_BYTE_REGS))
                    {
                        // Pick a Byte register to use for op1
                        regByteMask = rpPredictRegPick(TYP_BYTE, PREDICT_REG, lockedRegs | rsvdRegs);
                        op1ByteMask = regByteMask;
                    }

                    if (!(op2->gtUsedRegs & RBM_BYTE_REGS))
                    {
                        // Pick a Byte register to use for op2, avoiding the one used by op1
                        regByteMask |= rpPredictRegPick(TYP_BYTE, PREDICT_REG, lockedRegs | rsvdRegs | op1ByteMask);
                    }

                    if (regByteMask)
                    {
                        tree->gtUsedRegs |= regByteMask;
                        regMask = regByteMask;
                    }
                }
#endif
                goto RETURN_CHECK;

            case GT_DIV:
            case GT_MOD:

            case GT_UDIV:
            case GT_UMOD:

                /* non-integer division handled in generic way */
                if (!varTypeIsIntegral(type))
                {
                    tree->gtUsedRegs = 0;
                    if (predictReg <= PREDICT_REG)
                        predictReg = PREDICT_SCRATCH_REG;
                    goto GENERIC_BINARY;
                }

#ifndef _TARGET_64BIT_

                if (type == TYP_LONG && (oper == GT_MOD || oper == GT_UMOD))
                {
                    /* Special case:  a mod with an int op2 is done inline using idiv or div
                       to avoid a costly call to the helper */

                    noway_assert((op2->gtOper == GT_CNS_LNG) &&
                                 (op2->gtLngCon.gtLconVal == int(op2->gtLngCon.gtLconVal)));

#if defined(_TARGET_X86_) || defined(_TARGET_ARM_)
                    if (tree->gtFlags & GTF_REVERSE_OPS)
                    {
                        tmpMask = rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs | RBM_PAIR_TMP,
                                                      rsvdRegs | op1->gtRsvdRegs);
                        tmpMask |= rpPredictTreeRegUse(op1, PREDICT_PAIR_TMP, lockedRegs | tmpMask, RBM_LASTUSE);
                    }
                    else
                    {
                        tmpMask = rpPredictTreeRegUse(op1, PREDICT_PAIR_TMP, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                        tmpMask |=
                            rpPredictTreeRegUse(op2, PREDICT_REG, lockedRegs | tmpMask | RBM_PAIR_TMP, RBM_LASTUSE);
                    }
                    regMask = RBM_PAIR_TMP;
#else // !_TARGET_X86_ && !_TARGET_ARM_
#error "Non-ARM or x86 _TARGET_ in RegPredict for 64-bit MOD"
#endif // !_TARGET_X86_ && !_TARGET_ARM_

                    tree->gtUsedRegs =
                        (regMaskSmall)(regMask | op1->gtUsedRegs | op2->gtUsedRegs |
                                       rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, regMask | tmpMask));

                    goto RETURN_CHECK;
                }
#endif // _TARGET_64BIT_

                /* no divide immediate, so force integer constant which is not
                 * a power of two to register
                 */

                if (op2->OperKind() & GTK_CONST)
                {
                    ssize_t ival = op2->gtIntConCommon.IconValue();

                    /* Is the divisor a power of 2 ? */

                    if (ival > 0 && genMaxOneBit(size_t(ival)))
                    {
                        goto GENERIC_UNARY;
                    }
                    else
                        op2PredictReg = PREDICT_SCRATCH_REG;
                }
                else
                {
                    /* Non integer constant also must be enregistered */
                    op2PredictReg = PREDICT_REG;
                }

                regMaskTP trashedMask;
                trashedMask = DUMMY_INIT(RBM_ILLEGAL);
                regMaskTP op1ExcludeMask;
                op1ExcludeMask = DUMMY_INIT(RBM_ILLEGAL);
                regMaskTP op2ExcludeMask;
                op2ExcludeMask = DUMMY_INIT(RBM_ILLEGAL);

#ifdef _TARGET_XARCH_
                /*  Consider the case "a / b" - we'll need to trash EDX (via "CDQ") before
                 *  we can safely allow the "b" value to die. Unfortunately, if we simply
                 *  mark the node "b" as using EDX, this will not work if "b" is a register
                 *  variable that dies with this particular reference. Thus, if we want to
                 *  avoid this situation (where we would have to spill the variable from
                 *  EDX to someplace else), we need to explicitly mark the interference
                 *  of the variable at this point.
                 */

                if (op2->gtOper == GT_LCL_VAR)
                {
                    unsigned lclNum = op2->gtLclVarCommon.gtLclNum;
                    varDsc          = lvaTable + lclNum;
                    if (varDsc->lvTracked)
                    {
#ifdef DEBUG
                        if (verbose)
                        {
                            if (!VarSetOps::IsMember(this, raLclRegIntf[REG_EAX], varDsc->lvVarIndex))
                                printf("Record interference between V%02u,T%02u and EAX -- int divide\n", lclNum,
                                       varDsc->lvVarIndex);
                            if (!VarSetOps::IsMember(this, raLclRegIntf[REG_EDX], varDsc->lvVarIndex))
                                printf("Record interference between V%02u,T%02u and EDX -- int divide\n", lclNum,
                                       varDsc->lvVarIndex);
                        }
#endif
                        VarSetOps::AddElemD(this, raLclRegIntf[REG_EAX], varDsc->lvVarIndex);
                        VarSetOps::AddElemD(this, raLclRegIntf[REG_EDX], varDsc->lvVarIndex);
                    }
                }

                /* set the held register based on opcode */
                if (oper == GT_DIV || oper == GT_UDIV)
                    regMask = RBM_EAX;
                else
                    regMask    = RBM_EDX;
                trashedMask    = (RBM_EAX | RBM_EDX);
                op1ExcludeMask = 0;
                op2ExcludeMask = (RBM_EAX | RBM_EDX);

#endif // _TARGET_XARCH_

#ifdef _TARGET_ARM_
                trashedMask    = RBM_NONE;
                op1ExcludeMask = RBM_NONE;
                op2ExcludeMask = RBM_NONE;
#endif

                /* set the lvPref reg if possible */
                GenTreePtr dest;
                /*
                 *  Walking the gtNext link twice from here should get us back
                 *  to our parent node, if this is an simple assignment tree.
                 */
                dest = tree->gtNext;
                if (dest && (dest->gtOper == GT_LCL_VAR) && dest->gtNext && (dest->gtNext->OperKind() & GTK_ASGOP) &&
                    dest->gtNext->gtOp.gtOp2 == tree)
                {
                    varDsc = lvaTable + dest->gtLclVarCommon.gtLclNum;
                    varDsc->addPrefReg(regMask, this);
                }
#ifdef _TARGET_XARCH_
                op1PredictReg = PREDICT_REG_EDX; /* Normally target op1 into EDX */
#else
                op1PredictReg        = PREDICT_SCRATCH_REG;
#endif

                /* are we supposed to evaluate op2 first? */
                if (tree->gtFlags & GTF_REVERSE_OPS)
                {
                    tmpMask = rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs | op2ExcludeMask,
                                                  rsvdRegs | op1->gtRsvdRegs);
                    rpPredictTreeRegUse(op1, op1PredictReg, lockedRegs | tmpMask | op1ExcludeMask, RBM_LASTUSE);
                }
                else
                {
                    tmpMask = rpPredictTreeRegUse(op1, op1PredictReg, lockedRegs | op1ExcludeMask,
                                                  rsvdRegs | op2->gtRsvdRegs);
                    rpPredictTreeRegUse(op2, op2PredictReg, tmpMask | lockedRegs | op2ExcludeMask, RBM_LASTUSE);
                }
#ifdef _TARGET_ARM_
                regMask = tmpMask;
#endif
                /* grab EAX, EDX for this tree node */
                tree->gtUsedRegs = (regMaskSmall)trashedMask | op1->gtUsedRegs | op2->gtUsedRegs;

                goto RETURN_CHECK;

            case GT_LSH:
            case GT_RSH:
            case GT_RSZ:

                if (predictReg <= PREDICT_REG)
                    predictReg = PREDICT_SCRATCH_REG;

#ifndef _TARGET_64BIT_
                if (type == TYP_LONG)
                {
                    if (op2->IsCnsIntOrI())
                    {
                        regMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);
                        // no register used by op2
                        op2->gtUsedRegs  = 0;
                        tree->gtUsedRegs = op1->gtUsedRegs;
                    }
                    else
                    {
                        // since RBM_LNGARG_0 and RBM_SHIFT_LNG are hardwired we can't have them in the locked registers
                        tmpMask = lockedRegs;
                        tmpMask &= ~RBM_LNGARG_0;
                        tmpMask &= ~RBM_SHIFT_LNG;

                        // op2 goes to RBM_SHIFT, op1 to the RBM_LNGARG_0 pair
                        if (tree->gtFlags & GTF_REVERSE_OPS)
                        {
                            rpPredictTreeRegUse(op2, PREDICT_REG_SHIFT_LNG, tmpMask, RBM_NONE);
                            tmpMask |= RBM_SHIFT_LNG;
                            // Ensure that the RBM_SHIFT_LNG register interfere with op2's compCurLife
                            // Fix 383843 X86/ARM ILGEN
                            rpRecordRegIntf(RBM_SHIFT_LNG, compCurLife DEBUGARG("SHIFT_LNG arg setup"));
                            rpPredictTreeRegUse(op1, PREDICT_PAIR_LNGARG_0, tmpMask, RBM_LASTUSE);
                        }
                        else
                        {
                            rpPredictTreeRegUse(op1, PREDICT_PAIR_LNGARG_0, tmpMask, RBM_NONE);
                            tmpMask |= RBM_LNGARG_0;
                            // Ensure that the RBM_LNGARG_0 registers interfere with op1's compCurLife
                            // Fix 383839 ARM ILGEN
                            rpRecordRegIntf(RBM_LNGARG_0, compCurLife DEBUGARG("LNGARG_0 arg setup"));
                            rpPredictTreeRegUse(op2, PREDICT_REG_SHIFT_LNG, tmpMask, RBM_LASTUSE);
                        }
                        regMask = RBM_LNGRET; // function return registers
                        op1->gtUsedRegs |= RBM_LNGARG_0;
                        op2->gtUsedRegs |= RBM_SHIFT_LNG;

                        tree->gtUsedRegs = op1->gtUsedRegs | op2->gtUsedRegs;

                        // We are using a helper function to do shift:
                        //
                        tree->gtUsedRegs |= RBM_CALLEE_TRASH;
                    }
                }
                else
#endif // _TARGET_64BIT_
                {
#ifdef _TARGET_XARCH_
                    if (!op2->IsCnsIntOrI())
                        predictReg = PREDICT_NOT_REG_ECX;
#endif

                HANDLE_SHIFT_COUNT:
                    // Note that this code is also used by assigning shift operators (i.e. GT_ASG_LSH)

                    regMaskTP tmpRsvdRegs;

                    if ((tree->gtFlags & GTF_REVERSE_OPS) == 0)
                    {
                        regMask     = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                        rsvdRegs    = RBM_LASTUSE;
                        tmpRsvdRegs = RBM_NONE;
                    }
                    else
                    {
                        regMask = RBM_NONE;
                        // Special case op1 of a constant
                        if (op1->IsCnsIntOrI())
                            tmpRsvdRegs = RBM_LASTUSE; // Allow a last use to occur in op2; See
                                                       // System.Xml.Schema.BitSet:Get(int):bool
                        else
                            tmpRsvdRegs = op1->gtRsvdRegs;
                    }

                    op2Mask = RBM_NONE;
                    if (!op2->IsCnsIntOrI())
                    {
                        if ((REG_SHIFT != REG_NA) && ((RBM_SHIFT & tmpRsvdRegs) == 0))
                        {
                            op2PredictReg = PREDICT_REG_SHIFT;
                        }
                        else
                        {
                            op2PredictReg = PREDICT_REG;
                        }

                        /* evaluate shift count into a register, likely the PREDICT_REG_SHIFT register */
                        op2Mask = rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs | regMask, tmpRsvdRegs);

                        // If our target arch has a REG_SHIFT register then
                        //     we set the PrefReg when we have a LclVar for op2
                        //     we add an interference with REG_SHIFT for any other LclVars alive at op2
                        if (REG_SHIFT != REG_NA)
                        {
                            VARSET_TP liveSet(VarSetOps::MakeCopy(this, compCurLife));

                            while (op2->gtOper == GT_COMMA)
                            {
                                op2 = op2->gtOp.gtOp2;
                            }

                            if (op2->gtOper == GT_LCL_VAR)
                            {
                                varDsc = lvaTable + op2->gtLclVarCommon.gtLclNum;
                                varDsc->setPrefReg(REG_SHIFT, this);
                                if (varDsc->lvTracked)
                                {
                                    VarSetOps::RemoveElemD(this, liveSet, varDsc->lvVarIndex);
                                }
                            }

                            // Ensure that we have a register interference with the LclVar in tree's LiveSet,
                            // excluding the LclVar that was used for the shift amount as it is read-only
                            // and can be kept alive through the shift operation
                            //
                            rpRecordRegIntf(RBM_SHIFT, liveSet DEBUGARG("Variable Shift Register"));
                            // In case op2Mask doesn't contain the required shift register,
                            // we will or it in now.
                            op2Mask |= RBM_SHIFT;
                        }
                    }

                    if (tree->gtFlags & GTF_REVERSE_OPS)
                    {
                        assert(regMask == RBM_NONE);
                        regMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs | op2Mask, rsvdRegs | RBM_LASTUSE);
                    }

#if CPU_HAS_BYTE_REGS
                    if (varTypeIsByte(type))
                    {
                        // Fix 383789 X86 ILGEN
                        // Fix 383813 X86 ILGEN
                        // Fix 383828 X86 ILGEN
                        if (op1->gtOper == GT_LCL_VAR)
                        {
                            varDsc = lvaTable + op1->gtLclVar.gtLclNum;
                            if (varDsc->lvTracked)
                            {
                                VARSET_TP op1VarBit(VarSetOps::MakeSingleton(this, varDsc->lvVarIndex));

                                // Ensure that we don't assign a Non-Byteable register for op1's LCL_VAR
                                rpRecordRegIntf(RBM_NON_BYTE_REGS, op1VarBit DEBUGARG("Non Byte Register"));
                            }
                        }
                        if ((regMask & RBM_BYTE_REGS) == 0)
                        {
                            // We need to grab a byte-able register, (i.e. EAX, EDX, ECX, EBX)
                            // and we can't select one that is already reserved (i.e. lockedRegs or regMask)
                            //
                            regMask |=
                                rpPredictRegPick(type, PREDICT_SCRATCH_REG, (lockedRegs | regMask | RBM_NON_BYTE_REGS));
                        }
                    }
#endif
                    tree->gtUsedRegs = (regMaskSmall)(regMask | op2Mask);
                }

                goto RETURN_CHECK;

            case GT_COMMA:
                if (tree->gtFlags & GTF_REVERSE_OPS)
                {
                    if (predictReg == PREDICT_NONE)
                    {
                        predictReg = PREDICT_REG;
                    }
                    else if (rpHasVarIndexForPredict(predictReg))
                    {
                        /* Don't propagate the use of tgt reg use in a GT_COMMA */
                        predictReg = PREDICT_SCRATCH_REG;
                    }

                    regMask = rpPredictTreeRegUse(op2, predictReg, lockedRegs, rsvdRegs);
                    rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs | regMask, RBM_LASTUSE);
                }
                else
                {
                    rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs, RBM_LASTUSE);

                    /* CodeGen will enregister the op2 side of a GT_COMMA */
                    if (predictReg == PREDICT_NONE)
                    {
                        predictReg = PREDICT_REG;
                    }
                    else if (rpHasVarIndexForPredict(predictReg))
                    {
                        /* Don't propagate the use of tgt reg use in a GT_COMMA */
                        predictReg = PREDICT_SCRATCH_REG;
                    }

                    regMask = rpPredictTreeRegUse(op2, predictReg, lockedRegs, rsvdRegs);
                }
                // tree should only accumulate the used registers from the op2 side of the GT_COMMA
                //
                tree->gtUsedRegs = op2->gtUsedRegs;
                if ((op2->gtOper == GT_LCL_VAR) && (rsvdRegs != 0))
                {
                    LclVarDsc* op2VarDsc = lvaTable + op2->gtLclVarCommon.gtLclNum;

                    if (op2VarDsc->lvTracked)
                    {
                        VARSET_TP op2VarBit(VarSetOps::MakeSingleton(this, op2VarDsc->lvVarIndex));
                        rpRecordRegIntf(rsvdRegs, op2VarBit DEBUGARG("comma use"));
                    }
                }
                goto RETURN_CHECK;

            case GT_QMARK:
            {
                noway_assert(op1 != NULL && op2 != NULL);

                /*
                 *  If the gtUsedRegs conflicts with lockedRegs
                 *  then we going to have to spill some registers
                 *  into the non-trashed register set to keep it alive
                 */
                unsigned spillCnt;
                spillCnt = 0;
                regMaskTP spillRegs;
                spillRegs = lockedRegs & tree->gtUsedRegs;

                while (spillRegs)
                {
                    /* Find the next register that needs to be spilled */
                    tmpMask = genFindLowestBit(spillRegs);

#ifdef DEBUG
                    if (verbose)
                    {
                        printf("Predict spill  of   %s before: ", getRegName(genRegNumFromMask(tmpMask)));
                        gtDispTree(tree, 0, NULL, true);
                    }
#endif
                    /* In Codegen it will typically introduce a spill temp here */
                    /* rather than relocating the register to a non trashed reg */
                    rpPredictSpillCnt++;
                    spillCnt++;

                    /* Remove it from the spillRegs and lockedRegs*/
                    spillRegs &= ~tmpMask;
                    lockedRegs &= ~tmpMask;
                }
                {
                    VARSET_TP startQmarkCondUseInPlaceVars(VarSetOps::MakeCopy(this, rpUseInPlace));

                    /* Evaluate the <cond> subtree */
                    rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs, RBM_LASTUSE);
                    VarSetOps::Assign(this, rpUseInPlace, startQmarkCondUseInPlaceVars);
                    tree->gtUsedRegs = op1->gtUsedRegs;

                    noway_assert(op2->gtOper == GT_COLON);
                    if (rpHasVarIndexForPredict(predictReg) && ((op2->gtFlags & (GTF_ASG | GTF_CALL)) != 0))
                    {
                        // Don't try to target the register specified in predictReg when we have complex subtrees
                        //
                        predictReg = PREDICT_SCRATCH_REG;
                    }
                    GenTreePtr elseTree = op2->AsColon()->ElseNode();
                    GenTreePtr thenTree = op2->AsColon()->ThenNode();

                    noway_assert(thenTree != NULL && elseTree != NULL);

                    // Update compCurLife to only those vars live on the <then> subtree

                    VarSetOps::Assign(this, compCurLife, tree->gtQmark.gtThenLiveSet);

                    if (type == TYP_VOID)
                    {
                        /* Evaluate the <then> subtree */
                        rpPredictTreeRegUse(thenTree, PREDICT_NONE, lockedRegs, RBM_LASTUSE);
                        regMask    = RBM_NONE;
                        predictReg = PREDICT_NONE;
                    }
                    else
                    {
                        // A mask to use to force the predictor to choose low registers (to reduce code size)
                        regMaskTP avoidRegs = RBM_NONE;
#ifdef _TARGET_ARM_
                        avoidRegs = (RBM_R12 | RBM_LR);
#endif
                        if (predictReg <= PREDICT_REG)
                            predictReg = PREDICT_SCRATCH_REG;

                        /* Evaluate the <then> subtree */
                        regMask =
                            rpPredictTreeRegUse(thenTree, predictReg, lockedRegs, rsvdRegs | avoidRegs | RBM_LASTUSE);

                        if (regMask)
                        {
                            rpPredictReg op1PredictReg = rpGetPredictForMask(regMask);
                            if (op1PredictReg != PREDICT_NONE)
                                predictReg = op1PredictReg;
                        }
                    }

                    VarSetOps::Assign(this, rpUseInPlace, startQmarkCondUseInPlaceVars);

                    /* Evaluate the <else> subtree */
                    // First record the post-then liveness, and reset the current liveness to the else
                    // branch liveness.
                    CLANG_FORMAT_COMMENT_ANCHOR;

#ifdef DEBUG
                    VARSET_TP postThenLive(VarSetOps::MakeCopy(this, compCurLife));
#endif

                    VarSetOps::Assign(this, compCurLife, tree->gtQmark.gtElseLiveSet);

                    rpPredictTreeRegUse(elseTree, predictReg, lockedRegs, rsvdRegs | RBM_LASTUSE);
                    tree->gtUsedRegs |= thenTree->gtUsedRegs | elseTree->gtUsedRegs;

                    // The then and the else are "virtual basic blocks" that form a control-flow diamond.
                    // They each have only one successor, which they share.  Their live-out sets must equal the
                    // live-in set of this virtual successor block, and thus must be the same.  We can assert
                    // that equality here.
                    assert(VarSetOps::Equal(this, compCurLife, postThenLive));

                    if (spillCnt > 0)
                    {
                        regMaskTP reloadMask = RBM_NONE;

                        while (spillCnt)
                        {
                            regMaskTP reloadReg;

                            /* Get an extra register to hold it */
                            reloadReg = rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | regMask | reloadMask);
#ifdef DEBUG
                            if (verbose)
                            {
                                printf("Predict reload into %s after : ", getRegName(genRegNumFromMask(reloadReg)));
                                gtDispTree(tree, 0, NULL, true);
                            }
#endif
                            reloadMask |= reloadReg;

                            spillCnt--;
                        }

                        /* update the gtUsedRegs mask */
                        tree->gtUsedRegs |= reloadMask;
                    }
                }

                goto RETURN_CHECK;
            }
            case GT_RETURN:
                tree->gtUsedRegs = RBM_NONE;
                regMask          = RBM_NONE;

                /* Is there a return value? */
                if (op1 != NULL)
                {
#if FEATURE_FP_REGALLOC
                    if (varTypeIsFloating(type))
                    {
                        predictReg = PREDICT_FLTRET;
                        if (type == TYP_FLOAT)
                            regMask = RBM_FLOATRET;
                        else
                            regMask = RBM_DOUBLERET;
                    }
                    else
#endif
                        if (isRegPairType(type))
                    {
                        predictReg = PREDICT_LNGRET;
                        regMask    = RBM_LNGRET;
                    }
                    else
                    {
                        predictReg = PREDICT_INTRET;
                        regMask    = RBM_INTRET;
                    }
                    if (info.compCallUnmanaged)
                    {
                        lockedRegs |= (RBM_PINVOKE_TCB | RBM_PINVOKE_FRAME);
                    }
                    rpPredictTreeRegUse(op1, predictReg, lockedRegs, RBM_LASTUSE);
                    tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                }

#if defined(_TARGET_ARM_) && defined(PROFILING_SUPPORTED)
                // When on Arm under profiler, to emit Leave callback we would need RBM_PROFILER_RETURN_USED.
                // We could optimize on registers based on int/long or no return value.  But to
                // keep it simple we will mark entire RBM_PROFILER_RETURN_USED as used regs here.
                if (compIsProfilerHookNeeded())
                {
                    tree->gtUsedRegs |= RBM_PROFILER_RET_USED;
                }

#endif
                goto RETURN_CHECK;

            case GT_RETFILT:
                if (op1 != NULL)
                {
                    rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs, RBM_LASTUSE);
                    regMask          = genReturnRegForTree(tree);
                    tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)regMask;
                    goto RETURN_CHECK;
                }
                tree->gtUsedRegs = 0;
                regMask          = 0;

                goto RETURN_CHECK;

            case GT_JTRUE:
                /* This must be a test of a relational operator */

                noway_assert(op1->OperIsCompare());

                /* Only condition code set by this operation */

                rpPredictTreeRegUse(op1, PREDICT_NONE, lockedRegs, RBM_NONE);

                tree->gtUsedRegs = op1->gtUsedRegs;
                regMask          = 0;

                goto RETURN_CHECK;

            case GT_SWITCH:
                noway_assert(type <= TYP_INT);
                noway_assert(compCurBB->bbJumpKind == BBJ_SWITCH);
#ifdef _TARGET_ARM_
                {
                    regMask          = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, RBM_NONE);
                    unsigned jumpCnt = compCurBB->bbJumpSwt->bbsCount;
                    if (jumpCnt > 2)
                    {
                        // Table based switch requires an extra register for the table base
                        regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regMask);
                    }
                    tree->gtUsedRegs = op1->gtUsedRegs | regMask;
                }
#else  // !_TARGET_ARM_
                rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, RBM_NONE);
                tree->gtUsedRegs = op1->gtUsedRegs;
#endif // _TARGET_ARM_
                regMask = 0;
                goto RETURN_CHECK;

            case GT_CKFINITE:
                if (predictReg <= PREDICT_REG)
                    predictReg = PREDICT_SCRATCH_REG;

                rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);
                // Need a reg to load exponent into
                regMask          = rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | rsvdRegs);
                tree->gtUsedRegs = (regMaskSmall)regMask | op1->gtUsedRegs;
                goto RETURN_CHECK;

            case GT_LCLHEAP:
                regMask = rpPredictTreeRegUse(op1, PREDICT_SCRATCH_REG, lockedRegs, rsvdRegs);
                op2Mask = 0;

#ifdef _TARGET_ARM_
                if (info.compInitMem)
                {
                    // We zero out two registers in the ARM codegen path
                    op2Mask |=
                        rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | rsvdRegs | regMask | op2Mask);
                }
#endif

                op1->gtUsedRegs |= (regMaskSmall)regMask;
                tree->gtUsedRegs = op1->gtUsedRegs | (regMaskSmall)op2Mask;

                // The result will be put in the reg we picked for the size
                // regMask = <already set as we want it to be>

                goto RETURN_CHECK;

            case GT_OBJ:
            {
#ifdef _TARGET_ARM_
                if (predictReg <= PREDICT_REG)
                    predictReg = PREDICT_SCRATCH_REG;

                regMaskTP avoidRegs = (RBM_R12 | RBM_LR); // A mask to use to force the predictor to choose low
                                                          // registers (to reduce code size)
                regMask = RBM_NONE;
                tmpMask = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs | avoidRegs);
#endif

                if (fgIsIndirOfAddrOfLocal(tree) != NULL)
                {
                    compUpdateLifeVar</*ForCodeGen*/ false>(tree);
                }

#ifdef _TARGET_ARM_
                unsigned  objSize   = info.compCompHnd->getClassSize(tree->gtObj.gtClass);
                regMaskTP preferReg = rpPredictRegMask(predictReg, TYP_I_IMPL);
                // If it has one bit set, and that's an arg reg...
                if (preferReg != RBM_NONE && genMaxOneBit(preferReg) && ((preferReg & RBM_ARG_REGS) != 0))
                {
                    // We are passing the 'obj' in the argument registers
                    //
                    regNumber rn = genRegNumFromMask(preferReg);

                    //  Add the registers used to pass the 'obj' to regMask.
                    for (unsigned i = 0; i < objSize / 4; i++)
                    {
                        if (rn == MAX_REG_ARG)
                            break;
                        // Otherwise...
                        regMask |= genRegMask(rn);
                        rn = genRegArgNext(rn);
                    }
                }
                else
                {
                    // We are passing the 'obj' in the outgoing arg space
                    // We will need one register to load into unless the 'obj' size is 4 or less.
                    //
                    if (objSize > 4)
                    {
                        regMask = rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | tmpMask | avoidRegs);
                    }
                }
                tree->gtUsedRegs = (regMaskSmall)(regMask | tmpMask);
                goto RETURN_CHECK;
#else  // !_TARGET_ARM
                goto GENERIC_UNARY;
#endif // _TARGET_ARM_
            }

            case GT_MKREFANY:
            {
#ifdef _TARGET_ARM_
                regMaskTP preferReg = rpPredictRegMask(predictReg, TYP_I_IMPL);
                regMask             = RBM_NONE;
                if ((((preferReg - 1) & preferReg) == 0) && ((preferReg & RBM_ARG_REGS) != 0))
                {
                    // A MKREFANY takes up two registers.
                    regNumber rn = genRegNumFromMask(preferReg);
                    regMask      = RBM_NONE;
                    if (rn < MAX_REG_ARG)
                    {
                        regMask |= genRegMask(rn);
                        rn = genRegArgNext(rn);
                        if (rn < MAX_REG_ARG)
                            regMask |= genRegMask(rn);
                    }
                }
                if (regMask != RBM_NONE)
                {
                    // Condensation of GENERIC_BINARY path.
                    assert((tree->gtFlags & GTF_REVERSE_OPS) == 0);
                    op2PredictReg        = PREDICT_REG;
                    regMaskTP regMaskOp1 = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs | op2->gtRsvdRegs);
                    rpPredictTreeRegUse(op2, op2PredictReg, lockedRegs | regMaskOp1, RBM_LASTUSE);
                    regMask |= op1->gtUsedRegs | op2->gtUsedRegs;
                    tree->gtUsedRegs = (regMaskSmall)regMask;
                    goto RETURN_CHECK;
                }
                tree->gtUsedRegs = op1->gtUsedRegs;
#endif // _TARGET_ARM_
                goto GENERIC_BINARY;
            }

            case GT_BOX:
                goto GENERIC_UNARY;

            case GT_LOCKADD:
                goto GENERIC_BINARY;

            case GT_XADD:
            case GT_XCHG:
                // Ensure we can write to op2.  op2 will hold the output.
                if (predictReg < PREDICT_SCRATCH_REG)
                    predictReg = PREDICT_SCRATCH_REG;

                if (tree->gtFlags & GTF_REVERSE_OPS)
                {
                    op2Mask = rpPredictTreeRegUse(op2, predictReg, lockedRegs, rsvdRegs);
                    regMask = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, rsvdRegs | op2Mask);
                }
                else
                {
                    regMask = rpPredictTreeRegUse(op1, PREDICT_REG, lockedRegs, rsvdRegs);
                    op2Mask = rpPredictTreeRegUse(op2, PREDICT_SCRATCH_REG, lockedRegs, rsvdRegs | regMask);
                }
                tree->gtUsedRegs = (regMaskSmall)(regMask | op2Mask);
                goto RETURN_CHECK;

            case GT_ARR_LENGTH:
                goto GENERIC_UNARY;

            case GT_INIT_VAL:
                // This unary operator simply passes through the value from its child (much like GT_NOP)
                // and thus won't need a scratch register.
                regMask          = rpPredictTreeRegUse(op1, predictReg, lockedRegs, rsvdRegs);
                tree->gtUsedRegs = op1->gtUsedRegs;
                goto RETURN_CHECK;

            default:
#ifdef DEBUG
                gtDispTree(tree);
#endif
                noway_assert(!"unexpected simple operator in reg use prediction");
                break;
        }
    }

    /* See what kind of a special operator we have here */

    switch (oper)
    {
        GenTreePtr      args;
        GenTreeArgList* list;
        regMaskTP       keepMask;
        unsigned        regArgsNum;
        int             regIndex;
        regMaskTP       regArgMask;
        regMaskTP       curArgMask;

        case GT_CALL:

        {

            /* initialize so we can just or in various bits */
            tree->gtUsedRegs = RBM_NONE;

#if GTF_CALL_REG_SAVE
            /*
             *  Unless the GTF_CALL_REG_SAVE flag is set,
             *  we can't preserve the RBM_CALLEE_TRASH registers.
             *  (likewise we can't preserve the return registers)
             *  So we remove them from the lockedRegs set and
             *  record any of them in the keepMask
             */

            if (tree->gtFlags & GTF_CALL_REG_SAVE)
            {
                regMaskTP trashMask = genReturnRegForTree(tree);

                keepMask = lockedRegs & trashMask;
                lockedRegs &= ~trashMask;
            }
            else
#endif
            {
                keepMask = lockedRegs & RBM_CALLEE_TRASH;
                lockedRegs &= ~RBM_CALLEE_TRASH;
            }

            regArgsNum = 0;
            regIndex   = 0;

            /* Is there an object pointer? */
            if (tree->gtCall.gtCallObjp)
            {
                /* Evaluate the instance pointer first */

                args = tree->gtCall.gtCallObjp;

                /* the objPtr always goes to an integer register (through temp or directly) */
                noway_assert(regArgsNum == 0);
                regArgsNum++;

                /* Must be passed in a register */

                noway_assert(args->gtFlags & GTF_LATE_ARG);

                /* Must be either a deferred reg arg node or a GT_ASG node */

                noway_assert(args->IsArgPlaceHolderNode() || args->IsNothingNode() || (args->gtOper == GT_ASG) ||
                             args->OperIsCopyBlkOp() || (args->gtOper == GT_COMMA));

                if (!args->IsArgPlaceHolderNode())
                {
                    rpPredictTreeRegUse(args, PREDICT_NONE, lockedRegs, RBM_LASTUSE);
                }
            }
            VARSET_TP startArgUseInPlaceVars(VarSetOps::UninitVal());
            VarSetOps::Assign(this, startArgUseInPlaceVars, rpUseInPlace);

            /* process argument list */
            for (list = tree->gtCall.gtCallArgs; list; list = list->Rest())
            {
                args = list->Current();

                if (args->gtFlags & GTF_LATE_ARG)
                {
                    /* Must be either a Placeholder/NOP node or a GT_ASG node */

                    noway_assert(args->IsArgPlaceHolderNode() || args->IsNothingNode() || (args->gtOper == GT_ASG) ||
                                 args->OperIsCopyBlkOp() || (args->gtOper == GT_COMMA));

                    if (!args->IsArgPlaceHolderNode())
                    {
                        rpPredictTreeRegUse(args, PREDICT_NONE, lockedRegs, RBM_LASTUSE);
                    }

                    regArgsNum++;
                }
                else
                {
#ifdef FEATURE_FIXED_OUT_ARGS
                    // We'll store this argument into the outgoing argument area
                    // It needs to be in a register to be stored.
                    //
                    predictReg = PREDICT_REG;

#else // !FEATURE_FIXED_OUT_ARGS
                    // We'll generate a push for this argument
                    //
                    predictReg = PREDICT_NONE;
                    if (varTypeIsSmall(args->TypeGet()))
                    {
                        /* We may need to sign or zero extend a small type using a register */
                        predictReg = PREDICT_SCRATCH_REG;
                    }
#endif

                    rpPredictTreeRegUse(args, predictReg, lockedRegs, RBM_LASTUSE);
                }
                VarSetOps::Assign(this, rpUseInPlace, startArgUseInPlaceVars);
                tree->gtUsedRegs |= args->gtUsedRegs;
            }

            /* Is there a late argument list */

            regIndex   = 0;
            regArgMask = RBM_NONE; // Set of argument registers that have already been setup.
            args       = NULL;

            /* process the late argument list */
            for (list = tree->gtCall.gtCallLateArgs; list; regIndex++)
            {
                // If the current argument being copied is a promoted struct local, set this pointer to its description.
                LclVarDsc* promotedStructLocal = NULL;

                curArgMask = RBM_NONE; // Set of argument registers that are going to be setup by this arg
                tmpMask    = RBM_NONE; // Set of additional temp registers that are need only to setup the current arg

                assert(list->OperIsList());

                args = list->Current();
                list = list->Rest();

                assert(!args->IsArgPlaceHolderNode()); // No place holders nodes are in gtCallLateArgs;

                fgArgTabEntryPtr curArgTabEntry = gtArgEntryByNode(tree->AsCall(), args);
                assert(curArgTabEntry);

                regNumber regNum = curArgTabEntry->regNum; // first register use to pass this argument
                unsigned  numSlots =
                    curArgTabEntry->numSlots; // number of outgoing arg stack slots used by this argument

                rpPredictReg argPredictReg;
                regMaskTP    avoidReg = RBM_NONE;

                if (regNum != REG_STK)
                {
                    argPredictReg = rpGetPredictForReg(regNum);
                    curArgMask |= genRegMask(regNum);
                }
                else
                {
                    assert(numSlots > 0);
                    argPredictReg = PREDICT_NONE;
#ifdef _TARGET_ARM_
                    // Force the predictor to choose a low register when regNum is REG_STK to reduce code bloat
                    avoidReg = (RBM_R12 | RBM_LR);
#endif
                }

#ifdef _TARGET_ARM_
                // For TYP_LONG or TYP_DOUBLE register arguments we need to add the second argument register
                //
                if ((regNum != REG_STK) && ((args->TypeGet() == TYP_LONG) || (args->TypeGet() == TYP_DOUBLE)))
                {
                    // 64-bit longs and doubles require 2 consecutive argument registers
                    curArgMask |= genRegMask(REG_NEXT(regNum));
                }
                else if (args->TypeGet() == TYP_STRUCT)
                {
                    GenTreePtr argx       = args;
                    GenTreePtr lclVarTree = NULL;

                    /* The GT_OBJ may be be a child of a GT_COMMA */
                    while (argx->gtOper == GT_COMMA)
                    {
                        argx = argx->gtOp.gtOp2;
                    }
                    unsigned originalSize = 0;

                    if (argx->gtOper == GT_OBJ)
                    {
                        originalSize = info.compCompHnd->getClassSize(argx->gtObj.gtClass);

                        // Is it the address of a promoted struct local?
                        if (argx->gtObj.gtOp1->gtOper == GT_ADDR && argx->gtObj.gtOp1->gtOp.gtOp1->gtOper == GT_LCL_VAR)
                        {
                            lclVarTree        = argx->gtObj.gtOp1->gtOp.gtOp1;
                            LclVarDsc* varDsc = &lvaTable[lclVarTree->gtLclVarCommon.gtLclNum];
                            if (varDsc->lvPromoted)
                                promotedStructLocal = varDsc;
                        }
                    }
                    else if (argx->gtOper == GT_LCL_VAR)
                    {
                        varDsc       = lvaTable + argx->gtLclVarCommon.gtLclNum;
                        originalSize = varDsc->lvSize();

                        // Is it a promoted struct local?
                        if (varDsc->lvPromoted)
                            promotedStructLocal = varDsc;
                    }
                    else if (argx->gtOper == GT_MKREFANY)
                    {
                        originalSize = 2 * TARGET_POINTER_SIZE;
                    }
                    else
                    {
                        noway_assert(!"Can't predict unsupported TYP_STRUCT arg kind");
                    }

                    // We only pass arguments differently if it a struct local "independently" promoted, which
                    // allows the field locals can be independently enregistered.
                    if (promotedStructLocal != NULL)
                    {
                        if (lvaGetPromotionType(promotedStructLocal) != PROMOTION_TYPE_INDEPENDENT)
                            promotedStructLocal = NULL;
                    }

                    unsigned slots = ((unsigned)(roundUp(originalSize, TARGET_POINTER_SIZE))) / REGSIZE_BYTES;

                    // Are we passing a TYP_STRUCT in multiple integer registers?
                    // if so set up curArgMask to reflect this
                    // Also slots is updated to reflect the number of outgoing arg slots that we will write
                    if (regNum != REG_STK)
                    {
                        regNumber regLast = (curArgTabEntry->isHfaRegArg) ? LAST_FP_ARGREG : REG_ARG_LAST;
                        assert(genIsValidReg(regNum));
                        regNumber nextReg = REG_NEXT(regNum);
                        slots--;
                        while (slots > 0 && nextReg <= regLast)
                        {
                            curArgMask |= genRegMask(nextReg);
                            nextReg = REG_NEXT(nextReg);
                            slots--;
                        }
                    }

                    if ((promotedStructLocal != NULL) && (curArgMask != RBM_NONE))
                    {
                        // All or a portion of this struct will be placed in the argument registers indicated by
                        // "curArgMask". We build in knowledge of the order in which the code is generated here, so
                        // that the second arg to be evaluated interferes with the reg for the first, the third with
                        // the regs for the first and second, etc. But since we always place the stack slots before
                        // placing the register slots we do not add inteferences for any part of the struct that gets
                        // passed on the stack.

                        argPredictReg =
                            PREDICT_NONE; // We will target the indivual fields into registers but not the whole struct
                        regMaskTP prevArgMask = RBM_NONE;
                        for (unsigned i = 0; i < promotedStructLocal->lvFieldCnt; i++)
                        {
                            LclVarDsc* fieldVarDsc = &lvaTable[promotedStructLocal->lvFieldLclStart + i];
                            if (fieldVarDsc->lvTracked)
                            {
                                assert(lclVarTree != NULL);
                                if (prevArgMask != RBM_NONE)
                                {
                                    rpRecordRegIntf(prevArgMask, VarSetOps::MakeSingleton(this, fieldVarDsc->lvVarIndex)
                                                                     DEBUGARG("fieldVar/argReg"));
                                }
                            }
                            // Now see many registers this uses up.
                            unsigned firstRegOffset = fieldVarDsc->lvFldOffset / TARGET_POINTER_SIZE;
                            unsigned nextAfterLastRegOffset =
                                (fieldVarDsc->lvFldOffset + fieldVarDsc->lvExactSize + TARGET_POINTER_SIZE - 1) /
                                TARGET_POINTER_SIZE;
                            unsigned nextAfterLastArgRegOffset =
                                min(nextAfterLastRegOffset,
                                    genIsValidIntReg(regNum) ? REG_NEXT(REG_ARG_LAST) : REG_NEXT(LAST_FP_ARGREG));

                            for (unsigned regOffset = firstRegOffset; regOffset < nextAfterLastArgRegOffset;
                                 regOffset++)
                            {
                                prevArgMask |= genRegMask(regNumber(regNum + regOffset));
                            }

                            if (nextAfterLastRegOffset > nextAfterLastArgRegOffset)
                            {
                                break;
                            }

                            if ((fieldVarDsc->lvFldOffset % TARGET_POINTER_SIZE) == 0)
                            {
                                // Add the argument register used here as a preferred register for this fieldVarDsc
                                //
                                regNumber firstRegUsed = regNumber(regNum + firstRegOffset);
                                fieldVarDsc->setPrefReg(firstRegUsed, this);
                            }
                        }
                        compUpdateLifeVar</*ForCodeGen*/ false>(argx);
                    }

                    // If slots is greater than zero then part or all of this TYP_STRUCT
                    // argument is passed in the outgoing argument area. (except HFA arg)
                    //
                    if ((slots > 0) && !curArgTabEntry->isHfaRegArg)
                    {
                        // We will need a register to address the TYP_STRUCT
                        // Note that we can use an argument register in curArgMask as in
                        // codegen we pass the stack portion of the argument before we
                        // setup the register part.
                        //

                        // Force the predictor to choose a LOW_REG here to reduce code bloat
                        avoidReg = (RBM_R12 | RBM_LR);

                        assert(tmpMask == RBM_NONE);
                        tmpMask = rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regArgMask | avoidReg);

                        // If slots > 1 then we will need a second register to perform the load/store into the outgoing
                        // arg area
                        if (slots > 1)
                        {
                            tmpMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG,
                                                        lockedRegs | regArgMask | tmpMask | avoidReg);
                        }
                    }
                } // (args->TypeGet() == TYP_STRUCT)
#endif            // _TARGET_ARM_

                // If we have a promotedStructLocal we don't need to call rpPredictTreeRegUse(args, ...
                // as we have already calculated the correct tmpMask and curArgMask values and
                // by calling rpPredictTreeRegUse we would just add unnecessary register inteferences.
                //
                if (promotedStructLocal == NULL)
                {
                    /* Target the appropriate argument register */
                    tmpMask |= rpPredictTreeRegUse(args, argPredictReg, lockedRegs | regArgMask, RBM_LASTUSE);
                }

                // We mark OBJ(ADDR(LOCAL)) with GTF_VAR_DEATH since the local is required to live
                // for the duration of the OBJ.
                if (args->OperGet() == GT_OBJ && (args->gtFlags & GTF_VAR_DEATH))
                {
                    GenTreePtr lclVarTree = fgIsIndirOfAddrOfLocal(args);
                    assert(lclVarTree != NULL); // Or else would not be marked with GTF_VAR_DEATH.
                    compUpdateLifeVar</*ForCodeGen*/ false>(lclVarTree);
                }

                regArgMask |= curArgMask;
                args->gtUsedRegs |= (tmpMask | regArgMask);
                tree->gtUsedRegs |= args->gtUsedRegs;
                tree->gtCall.gtCallLateArgs->gtUsedRegs |= args->gtUsedRegs;

                if (args->gtUsedRegs != RBM_NONE)
                {
                    // Add register interference with the set of registers used or in use when we evaluated
                    // the current arg, with whatever is alive after the current arg
                    //
                    rpRecordRegIntf(args->gtUsedRegs, compCurLife DEBUGARG("register arg setup"));
                }
                VarSetOps::Assign(this, rpUseInPlace, startArgUseInPlaceVars);
            }
            assert(list == NULL);

#ifdef LEGACY_BACKEND
#if CPU_LOAD_STORE_ARCH
#ifdef FEATURE_READYTORUN_COMPILER
            if (tree->gtCall.IsR2RRelativeIndir())
            {
                tree->gtUsedRegs |= RBM_R2R_INDIRECT_PARAM;
            }
#endif // FEATURE_READYTORUN_COMPILER
#endif // CPU_LOAD_STORE_ARCH
#endif // LEGACY_BACKEND

            regMaskTP callAddrMask;
            callAddrMask = RBM_NONE;
#if CPU_LOAD_STORE_ARCH
            predictReg = PREDICT_SCRATCH_REG;
#else
            predictReg       = PREDICT_NONE;
#endif

            switch (tree->gtFlags & GTF_CALL_VIRT_KIND_MASK)
            {
                case GTF_CALL_VIRT_STUB:

                    // We only want to record an interference between the virtual stub
                    // param reg and anything that's live AFTER the call, but we've not
                    // yet processed the indirect target.  So add virtualStubParamInfo.regMask
                    // to interferingRegs.
                    interferingRegs |= virtualStubParamInfo->GetRegMask();
#ifdef DEBUG
                    if (verbose)
                        printf("Adding interference with Virtual Stub Param\n");
#endif
                    codeGen->regSet.rsSetRegsModified(virtualStubParamInfo->GetRegMask());

                    if (tree->gtCall.gtCallType == CT_INDIRECT)
                    {
                        predictReg = virtualStubParamInfo->GetPredict();
                    }
                    break;

                case GTF_CALL_VIRT_VTABLE:
                    predictReg = PREDICT_SCRATCH_REG;
                    break;

                case GTF_CALL_NONVIRT:
                    predictReg = PREDICT_SCRATCH_REG;
                    break;
            }

            if (tree->gtCall.gtCallType == CT_INDIRECT)
            {
#if defined(_TARGET_ARM_) || defined(_TARGET_AMD64_)
                if (tree->gtCall.gtCallCookie)
                {
                    codeGen->regSet.rsSetRegsModified(RBM_PINVOKE_COOKIE_PARAM | RBM_PINVOKE_TARGET_PARAM);

                    callAddrMask |= rpPredictTreeRegUse(tree->gtCall.gtCallCookie, PREDICT_REG_PINVOKE_COOKIE_PARAM,
                                                        lockedRegs | regArgMask, RBM_LASTUSE);

                    // Just in case we predict some other registers, force interference with our two special
                    // parameters: PINVOKE_COOKIE_PARAM & PINVOKE_TARGET_PARAM
                    callAddrMask |= (RBM_PINVOKE_COOKIE_PARAM | RBM_PINVOKE_TARGET_PARAM);

                    predictReg = PREDICT_REG_PINVOKE_TARGET_PARAM;
                }
#endif
                callAddrMask |=
                    rpPredictTreeRegUse(tree->gtCall.gtCallAddr, predictReg, lockedRegs | regArgMask, RBM_LASTUSE);
            }
            else if (predictReg != PREDICT_NONE)
            {
                callAddrMask |= rpPredictRegPick(TYP_I_IMPL, predictReg, lockedRegs | regArgMask);
            }

            if (tree->gtFlags & GTF_CALL_UNMANAGED)
            {
                // Need a register for tcbReg
                callAddrMask |=
                    rpPredictRegPick(TYP_I_IMPL, PREDICT_SCRATCH_REG, lockedRegs | regArgMask | callAddrMask);
#if CPU_LOAD_STORE_ARCH
                // Need an extra register for tmpReg
                callAddrMask |=
                    rpPredictRegPick(TYP_I_IMPL, PREDICT_SCRATCH_REG, lockedRegs | regArgMask | callAddrMask);
#endif
            }

            tree->gtUsedRegs |= callAddrMask;

            /* After the call restore the orginal value of lockedRegs */
            lockedRegs |= keepMask;

            /* set the return register */
            regMask = genReturnRegForTree(tree);

            if (regMask & rsvdRegs)
            {
                // We will need to relocate the return register value
                regMaskTP intRegMask = (regMask & RBM_ALLINT);
#if FEATURE_FP_REGALLOC
                regMaskTP floatRegMask = (regMask & RBM_ALLFLOAT);
#endif
                regMask = RBM_NONE;

                if (intRegMask)
                {
                    if (intRegMask == RBM_INTRET)
                    {
                        regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, rsvdRegs | regMask);
                    }
                    else if (intRegMask == RBM_LNGRET)
                    {
                        regMask |= rpPredictRegPick(TYP_LONG, PREDICT_SCRATCH_REG, rsvdRegs | regMask);
                    }
                    else
                    {
                        noway_assert(!"unexpected return regMask");
                    }
                }

#if FEATURE_FP_REGALLOC
                if (floatRegMask)
                {
                    if (floatRegMask == RBM_FLOATRET)
                    {
                        regMask |= rpPredictRegPick(TYP_FLOAT, PREDICT_SCRATCH_REG, rsvdRegs | regMask);
                    }
                    else if (floatRegMask == RBM_DOUBLERET)
                    {
                        regMask |= rpPredictRegPick(TYP_DOUBLE, PREDICT_SCRATCH_REG, rsvdRegs | regMask);
                    }
                    else // HFA return case
                    {
                        for (unsigned f = 0; f < genCountBits(floatRegMask); f++)
                        {
                            regMask |= rpPredictRegPick(TYP_FLOAT, PREDICT_SCRATCH_REG, rsvdRegs | regMask);
                        }
                    }
                }
#endif
            }

            /* the return registers (if any) are killed */
            tree->gtUsedRegs |= regMask;

#if GTF_CALL_REG_SAVE
            if (!(tree->gtFlags & GTF_CALL_REG_SAVE))
#endif
            {
                /* the RBM_CALLEE_TRASH set are killed (i.e. EAX,ECX,EDX) */
                tree->gtUsedRegs |= RBM_CALLEE_TRASH;
            }
        }

#if defined(_TARGET_ARM_) && defined(PROFILING_SUPPORTED)
            // Mark required registers for emitting tailcall profiler callback as used
            if (compIsProfilerHookNeeded() && tree->gtCall.IsTailCall() && (tree->gtCall.gtCallType == CT_USER_FUNC))
            {
                tree->gtUsedRegs |= RBM_PROFILER_TAIL_USED;
            }
#endif
            break;

        case GT_ARR_ELEM:

            // Figure out which registers can't be touched
            unsigned dim;
            for (dim = 0; dim < tree->gtArrElem.gtArrRank; dim++)
                rsvdRegs |= tree->gtArrElem.gtArrInds[dim]->gtRsvdRegs;

            regMask = rpPredictTreeRegUse(tree->gtArrElem.gtArrObj, PREDICT_REG, lockedRegs, rsvdRegs);

            regMaskTP dimsMask;
            dimsMask = 0;

#if CPU_LOAD_STORE_ARCH
            // We need a register to load the bounds of the MD array
            regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regMask);
#endif

            for (dim = 0; dim < tree->gtArrElem.gtArrRank; dim++)
            {
                /* We need scratch registers to compute index-lower_bound.
                   Also, gtArrInds[0]'s register will be used as the second
                   addressability register (besides gtArrObj's) */

                regMaskTP dimMask = rpPredictTreeRegUse(tree->gtArrElem.gtArrInds[dim], PREDICT_SCRATCH_REG,
                                                        lockedRegs | regMask | dimsMask, rsvdRegs);
                if (dim == 0)
                    regMask |= dimMask;

                dimsMask |= dimMask;
            }
#ifdef _TARGET_XARCH_
            // INS_imul doesnt have an immediate constant.
            if (!jitIsScaleIndexMul(tree->gtArrElem.gtArrElemSize))
                regMask |= rpPredictRegPick(TYP_INT, PREDICT_SCRATCH_REG, lockedRegs | regMask | dimsMask);
#endif
            tree->gtUsedRegs = (regMaskSmall)(regMask | dimsMask);
            break;

        case GT_CMPXCHG:
        {
#ifdef _TARGET_XARCH_
            rsvdRegs |= RBM_EAX;
#endif
            if (tree->gtCmpXchg.gtOpLocation->OperGet() == GT_LCL_VAR)
            {
                regMask = rpPredictTreeRegUse(tree->gtCmpXchg.gtOpLocation, PREDICT_REG, lockedRegs, rsvdRegs);
            }
            else
            {
                regMask = rpPredictTreeRegUse(tree->gtCmpXchg.gtOpLocation, PREDICT_ADDR, lockedRegs, rsvdRegs);
            }
            op2Mask = rpPredictTreeRegUse(tree->gtCmpXchg.gtOpValue, PREDICT_REG, lockedRegs, rsvdRegs | regMask);

#ifdef _TARGET_XARCH_
            rsvdRegs &= ~RBM_EAX;
            tmpMask = rpPredictTreeRegUse(tree->gtCmpXchg.gtOpComparand, PREDICT_REG_EAX, lockedRegs,
                                          rsvdRegs | regMask | op2Mask);
            tree->gtUsedRegs = (regMaskSmall)(RBM_EAX | regMask | op2Mask | tmpMask);
            predictReg       = PREDICT_REG_EAX; // When this is done the result is always in EAX.
#else
            tmpMask          = 0;
            tree->gtUsedRegs = (regMaskSmall)(regMask | op2Mask | tmpMask);
#endif
        }
        break;

        case GT_ARR_BOUNDS_CHECK:
        {
            regMaskTP opArrLenRsvd = rsvdRegs | tree->gtBoundsChk.gtIndex->gtRsvdRegs;
            regMask = rpPredictTreeRegUse(tree->gtBoundsChk.gtArrLen, PREDICT_REG, lockedRegs, opArrLenRsvd);
            rpPredictTreeRegUse(tree->gtBoundsChk.gtIndex, PREDICT_REG, lockedRegs | regMask, RBM_LASTUSE);

            tree->gtUsedRegs =
                (regMaskSmall)regMask | tree->gtBoundsChk.gtArrLen->gtUsedRegs | tree->gtBoundsChk.gtIndex->gtUsedRegs;
        }
        break;

        default:
            NO_WAY("unexpected special operator in reg use prediction");
            break;
    }

RETURN_CHECK:

#ifdef DEBUG
    /* make sure we set them to something reasonable */
    if (tree->gtUsedRegs & RBM_ILLEGAL)
        noway_assert(!"used regs not set properly in reg use prediction");

    if (regMask & RBM_ILLEGAL)
        noway_assert(!"return value not set propery in reg use prediction");

#endif

    /*
     *  If the gtUsedRegs conflicts with lockedRegs
     *  then we going to have to spill some registers
     *  into the non-trashed register set to keep it alive
     */
    regMaskTP spillMask;
    spillMask = tree->gtUsedRegs & lockedRegs;

    if (spillMask)
    {
        while (spillMask)
        {
            /* Find the next register that needs to be spilled */
            tmpMask = genFindLowestBit(spillMask);

#ifdef DEBUG
            if (verbose)
            {
                printf("Predict spill  of   %s before: ", getRegName(genRegNumFromMask(tmpMask)));
                gtDispTree(tree, 0, NULL, true);
                if ((tmpMask & regMask) == 0)
                {
                    printf("Predict reload of   %s after : ", getRegName(genRegNumFromMask(tmpMask)));
                    gtDispTree(tree, 0, NULL, true);
                }
            }
#endif
            /* In Codegen it will typically introduce a spill temp here */
            /* rather than relocating the register to a non trashed reg */
            rpPredictSpillCnt++;

            /* Remove it from the spillMask */
            spillMask &= ~tmpMask;
        }
    }

    /*
     *  If the return registers in regMask conflicts with the lockedRegs
     *  then we allocate extra registers for the reload of the conflicting
     *  registers.
     *
     *  Set spillMask to the set of locked registers that have to be reloaded here.
     *  reloadMask is set to the extra registers that are used to reload
     *  the spilled lockedRegs.
     */

    noway_assert(regMask != DUMMY_INIT(RBM_ILLEGAL));
    spillMask = lockedRegs & regMask;

    if (spillMask)
    {
        /* Remove the spillMask from regMask */
        regMask &= ~spillMask;

        regMaskTP reloadMask = RBM_NONE;
        while (spillMask)
        {
            /* Get an extra register to hold it */
            regMaskTP reloadReg = rpPredictRegPick(TYP_INT, PREDICT_REG, lockedRegs | regMask | reloadMask);
#ifdef DEBUG
            if (verbose)
            {
                printf("Predict reload into %s after : ", getRegName(genRegNumFromMask(reloadReg)));
                gtDispTree(tree, 0, NULL, true);
            }
#endif
            reloadMask |= reloadReg;

            /* Remove it from the spillMask */
            spillMask &= ~genFindLowestBit(spillMask);
        }

        /* Update regMask to use the reloadMask */
        regMask |= reloadMask;

        /* update the gtUsedRegs mask */
        tree->gtUsedRegs |= (regMaskSmall)regMask;
    }

    regMaskTP regUse = tree->gtUsedRegs;
    regUse |= interferingRegs;

    if (!VarSetOps::IsEmpty(this, compCurLife))
    {
        // Add interference between the current set of live variables and
        //  the set of temporary registers need to evaluate the sub tree
        if (regUse)
        {
            rpRecordRegIntf(regUse, compCurLife DEBUGARG("tmp use"));
        }
    }

    if (rpAsgVarNum != -1)
    {
        // Add interference between the registers used (if any)
        // and the assignment target variable
        if (regUse)
        {
            rpRecordRegIntf(regUse, VarSetOps::MakeSingleton(this, rpAsgVarNum) DEBUGARG("tgt var tmp use"));
        }

        // Add a variable interference from rpAsgVarNum (i.e. the enregistered left hand
        // side of the assignment passed here using PREDICT_REG_VAR_Txx)
        // to the set of currently live variables. This new interference will prevent us
        // from using the register value used here for enregistering different live variable
        //
        if (!VarSetOps::IsEmpty(this, compCurLife))
        {
            rpRecordVarIntf(rpAsgVarNum, compCurLife DEBUGARG("asg tgt live conflict"));
        }
    }

    /* Do we need to resore the oldLastUseVars value */
    if (restoreLastUseVars)
    {
        /*  If we used a GT_ASG targeted register then we need to add
         *  a variable interference between any new last use variables
         *  and the GT_ASG targeted register
         */
        if (!VarSetOps::Equal(this, rpLastUseVars, oldLastUseVars) && rpAsgVarNum != -1)
        {
            rpRecordVarIntf(rpAsgVarNum, VarSetOps::Diff(this, rpLastUseVars, oldLastUseVars)
                                             DEBUGARG("asgn tgt last use conflict"));
        }
        VarSetOps::Assign(this, rpLastUseVars, oldLastUseVars);
    }

    return regMask;
}
#ifdef _PREFAST_
#pragma warning(pop)
#endif

#endif // LEGACY_BACKEND

/****************************************************************************/
/* Returns true when we must create an EBP frame
   This is used to force most managed methods to have EBP based frames
   which allows the ETW kernel stackwalker to walk the stacks of managed code
   this allows the kernel to perform light weight profiling
 */
bool Compiler::rpMustCreateEBPFrame(INDEBUG(const char** wbReason))
{
    bool result = false;
#ifdef DEBUG
    const char* reason = nullptr;
#endif

#if ETW_EBP_FRAMED
    if (!result && (opts.MinOpts() || opts.compDbgCode))
    {
        INDEBUG(reason = "Debug Code");
        result = true;
    }
    if (!result && (info.compMethodInfo->ILCodeSize > DEFAULT_MAX_INLINE_SIZE))
    {
        INDEBUG(reason = "IL Code Size");
        result = true;
    }
    if (!result && (fgBBcount > 3))
    {
        INDEBUG(reason = "BasicBlock Count");
        result = true;
    }
    if (!result && fgHasLoops)
    {
        INDEBUG(reason = "Method has Loops");
        result = true;
    }
    if (!result && (optCallCount >= 2))
    {
        INDEBUG(reason = "Call Count");
        result = true;
    }
    if (!result && (optIndirectCallCount >= 1))
    {
        INDEBUG(reason = "Indirect Call");
        result = true;
    }
#endif // ETW_EBP_FRAMED

    // VM wants to identify the containing frame of an InlinedCallFrame always
    // via the frame register never the stack register so we need a frame.
    if (!result && (optNativeCallCount != 0))
    {
        INDEBUG(reason = "Uses PInvoke");
        result = true;
    }

#ifdef _TARGET_ARM64_
    // TODO-ARM64-NYI: This is temporary: force a frame pointer-based frame until genFnProlog can handle non-frame
    // pointer frames.
    if (!result)
    {
        INDEBUG(reason = "Temporary ARM64 force frame pointer");
        result = true;
    }
#endif // _TARGET_ARM64_

#ifdef DEBUG
    if ((result == true) && (wbReason != nullptr))
    {
        *wbReason = reason;
    }
#endif

    return result;
}

#ifdef LEGACY_BACKEND // We don't use any of the old register allocator functions when LSRA is used instead.

/*****************************************************************************
 *
 *  Predict which variables will be assigned to registers
 *  This is x86 specific and only predicts the integer registers and
 *  must be conservative, any register that is predicted to be enregister
 *  must end up being enregistered.
 *
 *  The rpPredictTreeRegUse takes advantage of the LCL_VARS that are
 *  predicted to be enregistered to minimize calls to rpPredictRegPick.
 *
 */

#ifdef _PREFAST_
#pragma warning(push)
#pragma warning(disable : 21000) // Suppress PREFast warning about overly large function
#endif
regMaskTP Compiler::rpPredictAssignRegVars(regMaskTP regAvail)
{
    unsigned regInx;

    if (rpPasses <= rpPassesPessimize)
    {
        // Assume that we won't have to reverse EBP enregistration
        rpReverseEBPenreg = false;

        // Set the default rpFrameType based upon codeGen->isFramePointerRequired()
        if (codeGen->isFramePointerRequired() || codeGen->isFrameRequired())
            rpFrameType = FT_EBP_FRAME;
        else
            rpFrameType = FT_ESP_FRAME;
    }

#if !ETW_EBP_FRAMED
    // If we are using FPBASE as the frame register, we cannot also use it for
    // a local var
    if (rpFrameType == FT_EBP_FRAME)
    {
        regAvail &= ~RBM_FPBASE;
    }
#endif // !ETW_EBP_FRAMED

    rpStkPredict        = 0;
    rpPredictAssignMask = regAvail;

    raSetupArgMasks(&codeGen->intRegState);
#if !FEATURE_STACK_FP_X87
    raSetupArgMasks(&codeGen->floatRegState);
#endif

    // If there is a secret stub param, it is also live in
    if (info.compPublishStubParam)
    {
        codeGen->intRegState.rsCalleeRegArgMaskLiveIn |= RBM_SECRET_STUB_PARAM;
    }

    if (regAvail == RBM_NONE)
    {
        unsigned   lclNum;
        LclVarDsc* varDsc;

        for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
        {
#if FEATURE_STACK_FP_X87
            if (!varDsc->IsFloatRegType())
#endif
            {
                varDsc->lvRegNum = REG_STK;
                if (isRegPairType(varDsc->lvType))
                    varDsc->lvOtherReg = REG_STK;
            }
        }
    }

#ifdef DEBUG
    if (verbose)
    {
        printf("\nCompiler::rpPredictAssignRegVars pass #%d", rpPasses);
        printf("\n        Available registers = ");
        dspRegMask(regAvail);
        printf("\n");
    }
#endif

    if (regAvail == RBM_NONE)
    {
        return RBM_NONE;
    }

    /* We cannot change the lvVarIndexes at this point, so we  */
    /* can only re-order the existing set of tracked variables */
    /* Which will change the order in which we select the      */
    /* locals for enregistering.                               */

    assert(lvaTrackedFixed); // We should have already set this to prevent us from adding any new tracked variables.

    // Should not be set unless optimizing
    noway_assert((lvaSortAgain == false) || (opts.MinOpts() == false));

    if (lvaSortAgain)
        lvaSortOnly();

#ifdef DEBUG
    fgDebugCheckBBlist();
#endif

    /* Initialize the weighted count of variables that could have */
    /* been enregistered but weren't */
    unsigned refCntStk    = 0; // sum of     ref counts for all stack based variables
    unsigned refCntEBP    = 0; // sum of     ref counts for EBP enregistered variables
    unsigned refCntWtdEBP = 0; // sum of wtd ref counts for EBP enregistered variables
#if DOUBLE_ALIGN
    unsigned refCntStkParam;  // sum of     ref counts for all stack based parameters
    unsigned refCntWtdStkDbl; // sum of wtd ref counts for stack based doubles

#if FEATURE_STACK_FP_X87
    refCntStkParam  = raCntStkParamDblStackFP;
    refCntWtdStkDbl = raCntWtdStkDblStackFP;
    refCntStk       = raCntStkStackFP;
#else
    refCntStkParam  = 0;
    refCntWtdStkDbl = 0;
    refCntStk       = 0;
#endif // FEATURE_STACK_FP_X87

#endif // DOUBLE_ALIGN

    /* Set of registers used to enregister variables in the predition */
    regMaskTP regUsed = RBM_NONE;

    /*-------------------------------------------------------------------------
     *
     *  Predict/Assign the enregistered locals in ref-count order
     *
     */

    VARSET_TP unprocessedVars(VarSetOps::MakeFull(this));

    unsigned FPRegVarLiveInCnt;
    FPRegVarLiveInCnt = 0; // How many enregistered doubles are live on entry to the method

    LclVarDsc* varDsc;
    for (unsigned sortNum = 0; sortNum < lvaCount; sortNum++)
    {
        bool notWorthy = false;

        unsigned  varIndex;
        bool      isDouble;
        regMaskTP regAvailForType;
        var_types regType;
        regMaskTP avoidReg;
        unsigned  customVarOrderSize;
        regNumber customVarOrder[MAX_VAR_ORDER_SIZE];
        bool      firstHalf;
        regNumber saveOtherReg;

        varDsc = lvaRefSorted[sortNum];

#if FEATURE_STACK_FP_X87
        if (varTypeIsFloating(varDsc->TypeGet()))
        {
#ifdef DEBUG
            if (lvaIsFieldOfDependentlyPromotedStruct(varDsc))
            {
                // Field local of a PROMOTION_TYPE_DEPENDENT struct should not
                // be en-registered.
                noway_assert(!varDsc->lvRegister);
            }
#endif
            continue;
        }
#endif

        /* Check the set of invariant things that would prevent enregistration */

        /* Ignore the variable if it's not tracked */
        if (!varDsc->lvTracked)
            goto CANT_REG;

        /* Get hold of the index and the interference mask for the variable */
        varIndex = varDsc->lvVarIndex;

        // Remove 'varIndex' from unprocessedVars
        VarSetOps::RemoveElemD(this, unprocessedVars, varIndex);

        // Skip the variable if it's marked as DoNotEnregister.

        if (varDsc->lvDoNotEnregister)
            goto CANT_REG;

        /* TODO: For now if we have JMP all register args go to stack
         * TODO: Later consider extending the life of the argument or make a copy of it */

        if (compJmpOpUsed && varDsc->lvIsRegArg)
            goto CANT_REG;

        /* Skip the variable if the ref count is zero */

        if (varDsc->lvRefCnt == 0)
            goto CANT_REG;

        /* Ignore field of PROMOTION_TYPE_DEPENDENT type of promoted struct */

        if (lvaIsFieldOfDependentlyPromotedStruct(varDsc))
        {
            goto CANT_REG;
        }

        /* Is the unweighted ref count too low to be interesting? */

        if (!varDsc->lvIsStructField && // We do encourage enregistering field locals.
            (varDsc->lvRefCnt <= 1))
        {
            /* Sometimes it's useful to enregister a variable with only one use */
            /*   arguments referenced in loops are one example */

            if (varDsc->lvIsParam && varDsc->lvRefCntWtd > BB_UNITY_WEIGHT)
                goto OK_TO_ENREGISTER;

            /* If the variable has a preferred register set it may be useful to put it there */
            if (varDsc->lvPrefReg && varDsc->lvIsRegArg)
                goto OK_TO_ENREGISTER;

            /* Keep going; the table is sorted by "weighted" ref count */
            goto CANT_REG;
        }

    OK_TO_ENREGISTER:

        if (varTypeIsFloating(varDsc->TypeGet()))
        {
            regType         = varDsc->TypeGet();
            regAvailForType = regAvail & RBM_ALLFLOAT;
        }
        else
        {
            regType         = TYP_INT;
            regAvailForType = regAvail & RBM_ALLINT;
        }

#ifdef _TARGET_ARM_
        isDouble = (varDsc->TypeGet() == TYP_DOUBLE);

        if (isDouble)
        {
            regAvailForType &= RBM_DBL_REGS; // We must restrict the set to the double registers
        }
#endif

        /* If we don't have any registers available then skip the enregistration attempt */
        if (regAvailForType == RBM_NONE)
            goto NO_REG;

        // On the pessimize passes don't even try to enregister LONGS
        if (isRegPairType(varDsc->lvType))
        {
            if (rpPasses > rpPassesPessimize)
                goto NO_REG;
            else if (rpLostEnreg && (rpPasses == rpPassesPessimize))
                goto NO_REG;
        }

        // Set of registers to avoid when performing register allocation
        avoidReg = RBM_NONE;

        if (!varDsc->lvIsRegArg)
        {
            /* For local variables,
             *  avoid the incoming arguments,
             *  but only if you conflict with them */

            if (raAvoidArgRegMask != 0)
            {
                LclVarDsc* argDsc;
                LclVarDsc* argsEnd = lvaTable + info.compArgsCount;

                for (argDsc = lvaTable; argDsc < argsEnd; argDsc++)
                {
                    if (!argDsc->lvIsRegArg)
                        continue;

                    bool      isFloat  = argDsc->IsFloatRegType();
                    regNumber inArgReg = argDsc->lvArgReg;
                    regMaskTP inArgBit = genRegMask(inArgReg);

                    // Is this inArgReg in the raAvoidArgRegMask set?

                    if (!(raAvoidArgRegMask & inArgBit))
                        continue;

                    noway_assert(argDsc->lvIsParam);
                    noway_assert(inArgBit & (isFloat ? RBM_FLTARG_REGS : RBM_ARG_REGS));

                    unsigned locVarIndex = varDsc->lvVarIndex;
                    unsigned argVarIndex = argDsc->lvVarIndex;

                    /* Does this variable interfere with the arg variable ? */
                    if (VarSetOps::IsMember(this, lvaVarIntf[locVarIndex], argVarIndex))
                    {
                        noway_assert(VarSetOps::IsMember(this, lvaVarIntf[argVarIndex], locVarIndex));
                        /* Yes, so try to avoid the incoming arg reg */
                        avoidReg |= inArgBit;
                    }
                    else
                    {
                        noway_assert(!VarSetOps::IsMember(this, lvaVarIntf[argVarIndex], locVarIndex));
                    }
                }
            }
        }

        // Now we will try to predict which register the variable
        // could  be enregistered in

        customVarOrderSize = MAX_VAR_ORDER_SIZE;

        raSetRegVarOrder(regType, customVarOrder, &customVarOrderSize, varDsc->lvPrefReg, avoidReg);

        firstHalf    = false;
        saveOtherReg = DUMMY_INIT(REG_NA);

        for (regInx = 0; regInx < customVarOrderSize; regInx++)
        {
            regNumber regNum  = customVarOrder[regInx];
            regMaskTP regBits = genRegMask(regNum);

            /* Skip this register if it isn't available */
            if ((regAvailForType & regBits) == 0)
                continue;

            /* Skip this register if it interferes with the variable */

            if (VarSetOps::IsMember(this, raLclRegIntf[regNum], varIndex))
                continue;

            if (varTypeIsFloating(regType))
            {
#ifdef _TARGET_ARM_
                if (isDouble)
                {
                    regNumber regNext = REG_NEXT(regNum);
                    regBits |= genRegMask(regNext);

                    /* Skip if regNext interferes with the variable */
                    if (VarSetOps::IsMember(this, raLclRegIntf[regNext], varIndex))
                        continue;
                }
#endif
            }

            bool firstUseOfReg     = ((regBits & (regUsed | codeGen->regSet.rsGetModifiedRegsMask())) == 0);
            bool lessThanTwoRefWtd = (varDsc->lvRefCntWtd < (2 * BB_UNITY_WEIGHT));
            bool calleeSavedReg    = ((regBits & RBM_CALLEE_SAVED) != 0);

            /* Skip this register if the weighted ref count is less than two
               and we are considering a unused callee saved register */

            if (lessThanTwoRefWtd && // less than two references (weighted)
                firstUseOfReg &&     // first use of this register
                calleeSavedReg)      // callee saved register
            {
                unsigned int totalRefCntWtd = varDsc->lvRefCntWtd;

                // psc is abbeviation for possibleSameColor
                VARSET_TP pscVarSet(VarSetOps::Diff(this, unprocessedVars, lvaVarIntf[varIndex]));

                VarSetOps::Iter pscIndexIter(this, pscVarSet);
                unsigned        pscIndex = 0;
                while (pscIndexIter.NextElem(&pscIndex))
                {
                    LclVarDsc* pscVar = lvaTable + lvaTrackedToVarNum[pscIndex];
                    totalRefCntWtd += pscVar->lvRefCntWtd;
                    if (totalRefCntWtd > (2 * BB_UNITY_WEIGHT))
                        break;
                }

                if (totalRefCntWtd <= (2 * BB_UNITY_WEIGHT))
                {
                    notWorthy = true;
                    continue; // not worth spilling a callee saved register
                }
                // otherwise we will spill this callee saved registers,
                // because its uses when combined with the uses of
                // other yet to be processed candidates exceed our threshold.
                // totalRefCntWtd = totalRefCntWtd;
            }

            /* Looks good - mark the variable as living in the register */

            if (isRegPairType(varDsc->lvType))
            {
                if (firstHalf == false)
                {
                    /* Enregister the first half of the long */
                    varDsc->lvRegNum   = regNum;
                    saveOtherReg       = varDsc->lvOtherReg;
                    varDsc->lvOtherReg = REG_STK;
                    firstHalf          = true;
                }
                else
                {
                    /* Ensure 'well-formed' register pairs */
                    /* (those returned by gen[Pick|Grab]RegPair) */

                    if (regNum < varDsc->lvRegNum)
                    {
                        varDsc->lvOtherReg = varDsc->lvRegNum;
                        varDsc->lvRegNum   = regNum;
                    }
                    else
                    {
                        varDsc->lvOtherReg = regNum;
                    }
                    firstHalf = false;
                }
            }
            else
            {
                varDsc->lvRegNum = regNum;
#ifdef _TARGET_ARM_
                if (isDouble)
                {
                    varDsc->lvOtherReg = REG_NEXT(regNum);
                }
#endif
            }

            if (regNum == REG_FPBASE)
            {
                refCntEBP += varDsc->lvRefCnt;
                refCntWtdEBP += varDsc->lvRefCntWtd;
#if DOUBLE_ALIGN
                if (varDsc->lvIsParam)
                {
                    refCntStkParam += varDsc->lvRefCnt;
                }
#endif
            }

            /* Record this register in the regUsed set */
            regUsed |= regBits;

            /* The register is now ineligible for all interfering variables */

            VarSetOps::UnionD(this, raLclRegIntf[regNum], lvaVarIntf[varIndex]);

#ifdef _TARGET_ARM_
            if (isDouble)
            {
                regNumber       secondHalf = REG_NEXT(regNum);
                VarSetOps::Iter iter(this, lvaVarIntf[varIndex]);
                unsigned        intfIndex = 0;
                while (iter.NextElem(&intfIndex))
                {
                    VarSetOps::AddElemD(this, raLclRegIntf[secondHalf], intfIndex);
                }
            }
#endif

            /* If a register argument, remove its incoming register
             * from the "avoid" list */

            if (varDsc->lvIsRegArg)
            {
                raAvoidArgRegMask &= ~genRegMask(varDsc->lvArgReg);
#ifdef _TARGET_ARM_
                if (isDouble)
                {
                    raAvoidArgRegMask &= ~genRegMask(REG_NEXT(varDsc->lvArgReg));
                }
#endif
            }

            /* A variable of TYP_LONG can take two registers */
            if (firstHalf)
                continue;

            // Since we have successfully enregistered this variable it is
            // now time to move on and consider the next variable
            goto ENREG_VAR;
        }

        if (firstHalf)
        {
            noway_assert(isRegPairType(varDsc->lvType));

            /* This TYP_LONG is partially enregistered */

            noway_assert(saveOtherReg != DUMMY_INIT(REG_NA));

            if (varDsc->lvDependReg && (saveOtherReg != REG_STK))
            {
                rpLostEnreg = true;
            }

            raAddToStkPredict(varDsc->lvRefCntWtd);
            goto ENREG_VAR;
        }

    NO_REG:;
        if (varDsc->lvDependReg)
        {
            rpLostEnreg = true;
        }

        if (!notWorthy)
        {
            /* Weighted count of variables that could have been enregistered but weren't */
            raAddToStkPredict(varDsc->lvRefCntWtd);

            if (isRegPairType(varDsc->lvType) && (varDsc->lvOtherReg == REG_STK))
                raAddToStkPredict(varDsc->lvRefCntWtd);
        }

    CANT_REG:;
        varDsc->lvRegister = false;

        varDsc->lvRegNum = REG_STK;
        if (isRegPairType(varDsc->lvType))
            varDsc->lvOtherReg = REG_STK;

        /* unweighted count of variables that were not enregistered */

        refCntStk += varDsc->lvRefCnt;

#if DOUBLE_ALIGN
        if (varDsc->lvIsParam)
        {
            refCntStkParam += varDsc->lvRefCnt;
        }
        else
        {
            /* Is it a stack based double? */
            /* Note that double params are excluded since they can not be double aligned */
            if (varDsc->lvType == TYP_DOUBLE)
            {
                refCntWtdStkDbl += varDsc->lvRefCntWtd;
            }
        }
#endif
#ifdef DEBUG
        if (verbose)
        {
            printf("; ");
            gtDispLclVar((unsigned)(varDsc - lvaTable));
            if (varDsc->lvTracked)
                printf("T%02u", varDsc->lvVarIndex);
            else
                printf("   ");
            printf(" (refcnt=%2u,refwtd=%s) not enregistered", varDsc->lvRefCnt, refCntWtd2str(varDsc->lvRefCntWtd));
            if (varDsc->lvDoNotEnregister)
                printf(", do-not-enregister");
            printf("\n");
        }
#endif
        continue;

    ENREG_VAR:;

        varDsc->lvRegister = true;

        // Record the fact that we enregistered a stack arg when tail call is used.
        if (compJmpOpUsed && !varDsc->lvIsRegArg)
        {
            rpMaskPInvokeEpilogIntf |= genRegMask(varDsc->lvRegNum);
            if (isRegPairType(varDsc->lvType))
            {
                rpMaskPInvokeEpilogIntf |= genRegMask(varDsc->lvOtherReg);
            }
        }

#ifdef DEBUG
        if (verbose)
        {
            printf("; ");
            gtDispLclVar((unsigned)(varDsc - lvaTable));
            printf("T%02u (refcnt=%2u,refwtd=%s) predicted to be assigned to ", varIndex, varDsc->lvRefCnt,
                   refCntWtd2str(varDsc->lvRefCntWtd));
            varDsc->PrintVarReg();
#ifdef _TARGET_ARM_
            if (isDouble)
            {
                printf(":%s", getRegName(varDsc->lvOtherReg));
            }
#endif
            printf("\n");
        }
#endif
    }

#if ETW_EBP_FRAMED
    noway_assert(refCntEBP == 0);
#endif

#ifdef DEBUG
    if (verbose)
    {
        if (refCntStk > 0)
            printf("; refCntStk       = %u\n", refCntStk);
        if (refCntEBP > 0)
            printf("; refCntEBP       = %u\n", refCntEBP);
        if (refCntWtdEBP > 0)
            printf("; refCntWtdEBP    = %u\n", refCntWtdEBP);
#if DOUBLE_ALIGN
        if (refCntStkParam > 0)
            printf("; refCntStkParam  = %u\n", refCntStkParam);
        if (refCntWtdStkDbl > 0)
            printf("; refCntWtdStkDbl = %u\n", refCntWtdStkDbl);
#endif
    }
#endif

    /* Determine how the EBP register should be used */
    CLANG_FORMAT_COMMENT_ANCHOR;

#if DOUBLE_ALIGN

    if (!codeGen->isFramePointerRequired())
    {
        noway_assert(getCanDoubleAlign() < COUNT_DOUBLE_ALIGN);

        /*
            First let us decide if we should use EBP to create a
            double-aligned frame, instead of enregistering variables
        */

        if (getCanDoubleAlign() == MUST_DOUBLE_ALIGN)
        {
            rpFrameType = FT_DOUBLE_ALIGN_FRAME;
            goto REVERSE_EBP_ENREG;
        }

        if (getCanDoubleAlign() == CAN_DOUBLE_ALIGN && (refCntWtdStkDbl > 0))
        {
            if (shouldDoubleAlign(refCntStk, refCntEBP, refCntWtdEBP, refCntStkParam, refCntWtdStkDbl))
            {
                rpFrameType = FT_DOUBLE_ALIGN_FRAME;
                goto REVERSE_EBP_ENREG;
            }
        }
    }

#endif // DOUBLE_ALIGN

    if (!codeGen->isFramePointerRequired() && !codeGen->isFrameRequired())
    {
#ifdef _TARGET_XARCH_
// clang-format off
        /*  If we are using EBP to enregister variables then
            will we actually save bytes by setting up an EBP frame?

            Each stack reference is an extra byte of code if we use
            an ESP frame.

            Here we measure the savings that we get by using EBP to
            enregister variables vs. the cost in code size that we
            pay when using an ESP based frame.

            We pay one byte of code for each refCntStk
            but we save one byte (or more) for each refCntEBP.

            Our savings are the elimination of a stack memory read/write.
            We use the loop weighted value of
               refCntWtdEBP * mem_access_weight (0, 3, 6)
            to represent this savings.
         */

        // We also pay 5 extra bytes for the MOV EBP,ESP and LEA ESP,[EBP-0x10]
        // to set up an EBP frame in the prolog and epilog
        #define EBP_FRAME_SETUP_SIZE  5
        // clang-format on

        if (refCntStk > (refCntEBP + EBP_FRAME_SETUP_SIZE))
        {
            unsigned bytesSaved        = refCntStk - (refCntEBP + EBP_FRAME_SETUP_SIZE);
            unsigned mem_access_weight = 3;

            if (compCodeOpt() == SMALL_CODE)
                mem_access_weight = 0;
            else if (compCodeOpt() == FAST_CODE)
                mem_access_weight *= 2;

            if (bytesSaved > ((refCntWtdEBP * mem_access_weight) / BB_UNITY_WEIGHT))
            {
                /* It's not be a good idea to use EBP in our predictions */
                CLANG_FORMAT_COMMENT_ANCHOR;
#ifdef DEBUG
                if (verbose && (refCntEBP > 0))
                    printf("; Predicting that it's not worth using EBP to enregister variables\n");
#endif
                rpFrameType = FT_EBP_FRAME;
                goto REVERSE_EBP_ENREG;
            }
        }
#endif // _TARGET_XARCH_

        if ((rpFrameType == FT_NOT_SET) || (rpFrameType == FT_ESP_FRAME))
        {
#ifdef DEBUG
            const char* reason;
#endif
            if (rpMustCreateEBPCalled == false)
            {
                rpMustCreateEBPCalled = true;
                if (rpMustCreateEBPFrame(INDEBUG(&reason)))
                {
#ifdef DEBUG
                    if (verbose)
                        printf("; Decided to create an EBP based frame for ETW stackwalking (%s)\n", reason);
#endif
                    codeGen->setFrameRequired(true);

                    rpFrameType = FT_EBP_FRAME;
                    goto REVERSE_EBP_ENREG;
                }
            }
        }
    }

    goto EXIT;

REVERSE_EBP_ENREG:

    noway_assert(rpFrameType != FT_ESP_FRAME);

    rpReverseEBPenreg = true;

#if !ETW_EBP_FRAMED
    if (refCntEBP > 0)
    {
        noway_assert(regUsed & RBM_FPBASE);

        regUsed &= ~RBM_FPBASE;

        /* variables that were enregistered in EBP become stack based variables */
        raAddToStkPredict(refCntWtdEBP);

        unsigned lclNum;

        /* We're going to have to undo some predicted enregistered variables */
        for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
        {
            /* Is this a register variable? */
            if (varDsc->lvRegNum != REG_STK)
            {
                if (isRegPairType(varDsc->lvType))
                {
                    /* Only one can be EBP */
                    if (varDsc->lvRegNum == REG_FPBASE || varDsc->lvOtherReg == REG_FPBASE)
                    {
                        if (varDsc->lvRegNum == REG_FPBASE)
                            varDsc->lvRegNum = varDsc->lvOtherReg;

                        varDsc->lvOtherReg = REG_STK;

                        if (varDsc->lvRegNum == REG_STK)
                            varDsc->lvRegister = false;

                        if (varDsc->lvDependReg)
                            rpLostEnreg = true;
#ifdef DEBUG
                        if (verbose)
                            goto DUMP_MSG;
#endif
                    }
                }
                else
                {
                    if ((varDsc->lvRegNum == REG_FPBASE) && (!varDsc->IsFloatRegType()))
                    {
                        varDsc->lvRegNum = REG_STK;

                        varDsc->lvRegister = false;

                        if (varDsc->lvDependReg)
                            rpLostEnreg = true;
#ifdef DEBUG
                        if (verbose)
                        {
                        DUMP_MSG:
                            printf("; reversing enregisteration of V%02u,T%02u (refcnt=%2u,refwtd=%4u%s)\n", lclNum,
                                   varDsc->lvVarIndex, varDsc->lvRefCnt, varDsc->lvRefCntWtd / 2,
                                   (varDsc->lvRefCntWtd & 1) ? ".5" : "");
                        }
#endif
                    }
                }
            }
        }
    }
#endif // ETW_EBP_FRAMED

EXIT:;

    unsigned lclNum;
    for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
    {
        /* Clear the lvDependReg flag for next iteration of the predictor */
        varDsc->lvDependReg = false;

        // If we set rpLostEnreg and this is the first pessimize pass
        // then reverse the enreg of all TYP_LONG
        if (rpLostEnreg && isRegPairType(varDsc->lvType) && (rpPasses == rpPassesPessimize))
        {
            varDsc->lvRegNum   = REG_STK;
            varDsc->lvOtherReg = REG_STK;
        }
    }

#ifdef DEBUG
    if (verbose && raNewBlocks)
    {
        printf("\nAdded FP register killing blocks:\n");
        fgDispBasicBlocks();
        printf("\n");
    }
#endif
    noway_assert(rpFrameType != FT_NOT_SET);

    /* return the set of registers used to enregister variables */
    return regUsed;
}
#ifdef _PREFAST_
#pragma warning(pop)
#endif

/*****************************************************************************
 *
 *  Predict register use for every tree in the function. Note that we do this
 *  at different times (not to mention in a totally different way) for x86 vs
 *  RISC targets.
 */
void Compiler::rpPredictRegUse()
{
#ifdef DEBUG
    if (verbose)
        raDumpVarIntf();
#endif

    // We might want to adjust the ref counts based on interference
    raAdjustVarIntf();

    regMaskTP allAcceptableRegs = RBM_ALLINT;

#if FEATURE_FP_REGALLOC
    allAcceptableRegs |= raConfigRestrictMaskFP();
#endif

    allAcceptableRegs &= ~codeGen->regSet.rsMaskResvd; // Remove any register reserved for special purposes

    /* For debuggable code, genJumpToThrowHlpBlk() generates an inline call
       to acdHelper(). This is done implicitly, without creating a GT_CALL
       node. Hence, this interference is be handled implicitly by
       restricting the registers used for enregistering variables */

    if (opts.compDbgCode)
    {
        allAcceptableRegs &= RBM_CALLEE_SAVED;
    }

    /* Compute the initial regmask to use for the first pass */
    regMaskTP regAvail = RBM_CALLEE_SAVED & allAcceptableRegs;
    regMaskTP regUsed;

#if CPU_USES_BLOCK_MOVE
    /* If we might need to generate a rep mov instruction */
    /* remove ESI and EDI */
    if (compBlkOpUsed)
        regAvail &= ~(RBM_ESI | RBM_EDI);
#endif

#ifdef _TARGET_X86_
    /* If we using longs then we remove ESI to allow */
    /* ESI:EBX to be saved accross a call */
    if (compLongUsed)
        regAvail &= ~(RBM_ESI);
#endif

#ifdef _TARGET_ARM_
    // For the first register allocation pass we don't want to color using r4
    // as we want to allow it to be used to color the internal temps instead
    // when r0,r1,r2,r3 are all in use.
    //
    regAvail &= ~(RBM_R4);
#endif

#if ETW_EBP_FRAMED
    // We never have EBP available when ETW_EBP_FRAME is defined
    regAvail &= ~RBM_FPBASE;
#else
    /* If a frame pointer is required then we remove EBP */
    if (codeGen->isFramePointerRequired() || codeGen->isFrameRequired())
        regAvail &= ~RBM_FPBASE;
#endif

#ifdef DEBUG
    BOOL fJitNoRegLoc = JitConfig.JitNoRegLoc();
    if (fJitNoRegLoc)
        regAvail = RBM_NONE;
#endif

    if ((opts.compFlags & CLFLG_REGVAR) == 0)
        regAvail = RBM_NONE;

#if FEATURE_STACK_FP_X87
    VarSetOps::AssignNoCopy(this, optAllNonFPvars, VarSetOps::MakeEmpty(this));
    VarSetOps::AssignNoCopy(this, optAllFloatVars, VarSetOps::MakeEmpty(this));

    // Calculate the set of all tracked FP/non-FP variables
    //  into optAllFloatVars and optAllNonFPvars

    unsigned   lclNum;
    LclVarDsc* varDsc;

    for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
    {
        /* Ignore the variable if it's not tracked */

        if (!varDsc->lvTracked)
            continue;

        /* Get hold of the index and the interference mask for the variable */

        unsigned varNum = varDsc->lvVarIndex;

        /* add to the set of all tracked FP/non-FP variables */

        if (varDsc->IsFloatRegType())
            VarSetOps::AddElemD(this, optAllFloatVars, varNum);
        else
            VarSetOps::AddElemD(this, optAllNonFPvars, varNum);
    }
#endif

    for (unsigned i = 0; i < REG_COUNT; i++)
    {
        VarSetOps::AssignNoCopy(this, raLclRegIntf[i], VarSetOps::MakeEmpty(this));
    }
    for (unsigned i = 0; i < lvaTrackedCount; i++)
    {
        VarSetOps::AssignNoCopy(this, lvaVarPref[i], VarSetOps::MakeEmpty(this));
    }

    raNewBlocks          = false;
    rpPredictAssignAgain = false;
    rpPasses             = 0;

    bool      mustPredict   = true;
    unsigned  stmtNum       = 0;
    unsigned  oldStkPredict = DUMMY_INIT(~0);
    VARSET_TP oldLclRegIntf[REG_COUNT];

    for (unsigned i = 0; i < REG_COUNT; i++)
    {
        VarSetOps::AssignNoCopy(this, oldLclRegIntf[i], VarSetOps::MakeEmpty(this));
    }

    while (true)
    {
        /* Assign registers to variables using the variable/register interference
           graph (raLclRegIntf[]) calculated in the previous pass */
        regUsed = rpPredictAssignRegVars(regAvail);

        mustPredict |= rpLostEnreg;

#ifdef _TARGET_ARM_
        // See if we previously reserved REG_R10 and try to make it available if we have a small frame now
        if ((rpPasses == 0) && ((codeGen->regSet.rsMaskResvd & RBM_OPT_RSVD) != 0) &&
            !compRsvdRegCheck(REGALLOC_FRAME_LAYOUT))
        {
            // We can release our reservation on R10 and use it to color registers
            codeGen->regSet.rsMaskResvd &= ~RBM_OPT_RSVD;
            allAcceptableRegs |= RBM_OPT_RSVD;
        }
#endif

        /* Is our new prediction good enough?? */
        if (!mustPredict)
        {
            /* For small methods (less than 12 stmts), we add a    */
            /*   extra pass if we are predicting the use of some   */
            /*   of the caller saved registers.                    */
            /* This fixes RAID perf bug 43440 VB Ackerman function */

            if ((rpPasses == 1) && (stmtNum <= 12) && (regUsed & RBM_CALLEE_SAVED))
            {
                goto EXTRA_PASS;
            }

            /* If every variable was fully enregistered then we're done */
            if (rpStkPredict == 0)
                goto ALL_DONE;

            // This was a successful prediction.  Record it, in case it turns out to be the best one.
            rpRecordPrediction();

            if (rpPasses > 1)
            {
                noway_assert(oldStkPredict != (unsigned)DUMMY_INIT(~0));

                // Be careful about overflow
                unsigned highStkPredict = (rpStkPredict * 2 < rpStkPredict) ? ULONG_MAX : rpStkPredict * 2;
                if (oldStkPredict < highStkPredict)
                    goto ALL_DONE;

                if (rpStkPredict < rpPasses * 8)
                    goto ALL_DONE;

                if (rpPasses >= (rpPassesMax - 1))
                    goto ALL_DONE;
            }

        EXTRA_PASS:
            /* We will do another pass */;
        }

#ifdef DEBUG
        if (JitConfig.JitAssertOnMaxRAPasses())
        {
            noway_assert(rpPasses < rpPassesMax &&
                         "This may not a bug, but dev team should look and see what is happening");
        }
#endif

        // The "64" here had been "VARSET_SZ".  It is unclear why this number is connected with
        // the (max) size of a VARSET.  We've eliminated this constant, so I left this as a constant.  We hope
        // that we're phasing out this code, anyway, and this leaves the behavior the way that it was.
        if (rpPasses > (rpPassesMax - rpPassesPessimize) + 64)
        {
            NO_WAY("we seem to be stuck in an infinite loop. breaking out");
        }

#ifdef DEBUG
        if (verbose)
        {
            if (rpPasses > 0)
            {
                if (rpLostEnreg)
                    printf("\n; Another pass due to rpLostEnreg");
                if (rpAddedVarIntf)
                    printf("\n; Another pass due to rpAddedVarIntf");
                if ((rpPasses == 1) && rpPredictAssignAgain)
                    printf("\n; Another pass due to rpPredictAssignAgain");
            }
            printf("\n; Register predicting pass# %d\n", rpPasses + 1);
        }
#endif

        /*  Zero the variable/register interference graph */
        for (unsigned i = 0; i < REG_COUNT; i++)
        {
            VarSetOps::OldStyleClearD(this, raLclRegIntf[i]);
        }

        // if there are PInvoke calls and compLvFrameListRoot is enregistered,
        // it must not be in a register trashed by the callee
        if (info.compLvFrameListRoot != BAD_VAR_NUM)
        {
            assert(!opts.ShouldUsePInvokeHelpers());
            noway_assert(info.compLvFrameListRoot < lvaCount);

            LclVarDsc* pinvokeVarDsc = &lvaTable[info.compLvFrameListRoot];

            if (pinvokeVarDsc->lvTracked)
            {
                rpRecordRegIntf(RBM_CALLEE_TRASH, VarSetOps::MakeSingleton(this, pinvokeVarDsc->lvVarIndex)
                                                      DEBUGARG("compLvFrameListRoot"));

                // We would prefer to have this be enregister in the PINVOKE_TCB register
                pinvokeVarDsc->addPrefReg(RBM_PINVOKE_TCB, this);
            }

            // If we're using a single return block, the p/invoke epilog code trashes ESI and EDI (in the
            // worst case).  Make sure that the return value compiler temp that we create for the single
            // return block knows about this interference.
            if (genReturnLocal != BAD_VAR_NUM)
            {
                noway_assert(genReturnBB);
                LclVarDsc* localTmp = &lvaTable[genReturnLocal];
                if (localTmp->lvTracked)
                {
                    rpRecordRegIntf(RBM_PINVOKE_TCB | RBM_PINVOKE_FRAME,
                                    VarSetOps::MakeSingleton(this, localTmp->lvVarIndex) DEBUGARG("genReturnLocal"));
                }
            }
        }

#ifdef _TARGET_ARM_
        if (compFloatingPointUsed)
        {
            bool hasMustInitFloat = false;

            // if we have any must-init floating point LclVars then we will add register interferences
            // for the arguments with RBM_SCRATCH
            // this is so that if we need to reset the initReg to REG_SCRATCH in Compiler::genFnProlog()
            // we won't home the arguments into REG_SCRATCH

            unsigned   lclNum;
            LclVarDsc* varDsc;

            for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
            {
                if (varDsc->lvMustInit && varTypeIsFloating(varDsc->TypeGet()))
                {
                    hasMustInitFloat = true;
                    break;
                }
            }

            if (hasMustInitFloat)
            {
                for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
                {
                    // If is an incoming argument, that is tracked and not floating-point
                    if (varDsc->lvIsParam && varDsc->lvTracked && !varTypeIsFloating(varDsc->TypeGet()))
                    {
                        rpRecordRegIntf(RBM_SCRATCH, VarSetOps::MakeSingleton(this, varDsc->lvVarIndex)
                                                         DEBUGARG("arg home with must-init fp"));
                    }
                }
            }
        }
#endif

        stmtNum        = 0;
        rpAddedVarIntf = false;
        rpLostEnreg    = false;

        /* Walk the basic blocks and predict reg use for each tree */

        for (BasicBlock* block = fgFirstBB; block != NULL; block = block->bbNext)
        {
            GenTreePtr stmt;
            compCurBB       = block;
            compCurLifeTree = NULL;
            VarSetOps::Assign(this, compCurLife, block->bbLiveIn);

            compCurBB = block;

            for (stmt = block->FirstNonPhiDef(); stmt != NULL; stmt = stmt->gtNext)
            {
                noway_assert(stmt->gtOper == GT_STMT);

                rpPredictSpillCnt = 0;
                VarSetOps::AssignNoCopy(this, rpLastUseVars, VarSetOps::MakeEmpty(this));
                VarSetOps::AssignNoCopy(this, rpUseInPlace, VarSetOps::MakeEmpty(this));

                GenTreePtr tree = stmt->gtStmt.gtStmtExpr;
                stmtNum++;
#ifdef DEBUG
                if (verbose && 1)
                {
                    printf("\nRegister predicting BB%02u, stmt %d\n", block->bbNum, stmtNum);
                    gtDispTree(tree);
                    printf("\n");
                }
#endif
                rpPredictTreeRegUse(tree, PREDICT_NONE, RBM_NONE, RBM_NONE);

                noway_assert(rpAsgVarNum == -1);

                if (rpPredictSpillCnt > tmpIntSpillMax)
                    tmpIntSpillMax = rpPredictSpillCnt;
            }
        }
        rpPasses++;

        /* Decide whether we need to set mustPredict */
        mustPredict = false;

#ifdef _TARGET_ARM_
        // The spill count may be now high enough that we now need to reserve r10. If this is the case, we'll need to
        // reserve r10, and if it was used, throw out the last prediction and repredict.
        if (((codeGen->regSet.rsMaskResvd & RBM_OPT_RSVD) == 0) && compRsvdRegCheck(REGALLOC_FRAME_LAYOUT))
        {
            codeGen->regSet.rsMaskResvd |= RBM_OPT_RSVD;
            allAcceptableRegs &= ~RBM_OPT_RSVD;
            if ((regUsed & RBM_OPT_RSVD) != 0)
            {
                mustPredict              = true;
                rpBestRecordedPrediction = nullptr;
            }
        }
#endif

        if (rpAddedVarIntf)
        {
            mustPredict = true;
#ifdef DEBUG
            if (verbose)
                raDumpVarIntf();
#endif
        }

        if (rpPasses == 1)
        {
            if ((opts.compFlags & CLFLG_REGVAR) == 0)
                goto ALL_DONE;

            if (rpPredictAssignAgain)
                mustPredict = true;
#ifdef DEBUG
            if (fJitNoRegLoc)
                goto ALL_DONE;
#endif
        }

        /* Calculate the new value to use for regAvail */

        regAvail = allAcceptableRegs;

        /* If a frame pointer is required then we remove EBP */
        if (codeGen->isFramePointerRequired() || codeGen->isFrameRequired())
            regAvail &= ~RBM_FPBASE;

#if ETW_EBP_FRAMED
        // We never have EBP available when ETW_EBP_FRAME is defined
        regAvail &= ~RBM_FPBASE;
#endif

        // If we have done n-passes then we must continue to pessimize the
        // interference graph by or-ing the interferences from the previous pass

        if (rpPasses > rpPassesPessimize)
        {
            for (unsigned regInx = 0; regInx < REG_COUNT; regInx++)
                VarSetOps::UnionD(this, raLclRegIntf[regInx], oldLclRegIntf[regInx]);

            /* If we reverse an EBP enregistration then keep it that way */
            if (rpReverseEBPenreg)
                regAvail &= ~RBM_FPBASE;
        }

#ifdef DEBUG
        if (verbose)
            raDumpRegIntf();
#endif

        /*  Save the old variable/register interference graph */
        for (unsigned i = 0; i < REG_COUNT; i++)
        {
            VarSetOps::Assign(this, oldLclRegIntf[i], raLclRegIntf[i]);
        }
        oldStkPredict = rpStkPredict;
    } // end of while (true)

ALL_DONE:;

    // If we recorded a better feasible allocation than we ended up with, go back to using it.
    rpUseRecordedPredictionIfBetter();

#if DOUBLE_ALIGN
    codeGen->setDoubleAlign(false);
#endif

    switch (rpFrameType)
    {
        default:
            noway_assert(!"rpFrameType not set correctly!");
            break;
        case FT_ESP_FRAME:
            noway_assert(!codeGen->isFramePointerRequired());
            noway_assert(!codeGen->isFrameRequired());
            codeGen->setFramePointerUsed(false);
            break;
        case FT_EBP_FRAME:
            noway_assert((regUsed & RBM_FPBASE) == 0);
            codeGen->setFramePointerUsed(true);
            break;
#if DOUBLE_ALIGN
        case FT_DOUBLE_ALIGN_FRAME:
            noway_assert((regUsed & RBM_FPBASE) == 0);
            noway_assert(!codeGen->isFramePointerRequired());
            codeGen->setFramePointerUsed(false);
            codeGen->setDoubleAlign(true);
            break;
#endif
    }

    /* Record the set of registers that we need */
    codeGen->regSet.rsClearRegsModified();
    if (regUsed != RBM_NONE)
    {
        codeGen->regSet.rsSetRegsModified(regUsed);
    }

    /* We need genFullPtrRegMap if :
     * The method is fully interruptible, or
     * We are generating an EBP-less frame (for stack-pointer deltas)
     */

    genFullPtrRegMap = (genInterruptible || !codeGen->isFramePointerUsed());

    raMarkStkVars();
#ifdef DEBUG
    if (verbose)
    {
        printf("# rpPasses was %u for %s\n", rpPasses, info.compFullName);
        printf("  rpStkPredict was %u\n", rpStkPredict);
    }
#endif
    rpRegAllocDone = true;
}

#endif // LEGACY_BACKEND

/*****************************************************************************
 *
 *  Mark all variables as to whether they live on the stack frame
 *  (part or whole), and if so what the base is (FP or SP).
 */

void Compiler::raMarkStkVars()
{
    unsigned   lclNum;
    LclVarDsc* varDsc;

    for (lclNum = 0, varDsc = lvaTable; lclNum < lvaCount; lclNum++, varDsc++)
    {
        // For RyuJIT, lvOnFrame is set by LSRA, except in the case of zero-ref, which is set below.
        CLANG_FORMAT_COMMENT_ANCHOR;

#ifdef LEGACY_BACKEND
        varDsc->lvOnFrame = false;
#endif // LEGACY_BACKEND

        if (lvaIsFieldOfDependentlyPromotedStruct(varDsc))
        {
            noway_assert(!varDsc->lvRegister);
            goto ON_STK;
        }

        /* Fully enregistered variables don't need any frame space */

        if (varDsc->lvRegister)
        {
            if (!isRegPairType(varDsc->TypeGet()))
            {
                goto NOT_STK;
            }

            /* For "large" variables make sure both halves are enregistered */

            if (varDsc->lvRegNum != REG_STK && varDsc->lvOtherReg != REG_STK)
            {
                goto NOT_STK;
            }
        }
        /* Unused variables typically don't get any frame space */
        else if (varDsc->lvRefCnt == 0)
        {
            bool needSlot = false;

            bool stkFixedArgInVarArgs =
                info.compIsVarArgs && varDsc->lvIsParam && !varDsc->lvIsRegArg && lclNum != lvaVarargsHandleArg;

            // If its address has been exposed, ignore lvRefCnt. However, exclude
            // fixed arguments in varargs method as lvOnFrame shouldn't be set
            // for them as we don't want to explicitly report them to GC.

            if (!stkFixedArgInVarArgs)
            {
                needSlot |= varDsc->lvAddrExposed;
            }

#if FEATURE_FIXED_OUT_ARGS

            /* Is this the dummy variable representing GT_LCLBLK ? */
            needSlot |= (lclNum == lvaOutgoingArgSpaceVar);

#endif // FEATURE_FIXED_OUT_ARGS

#ifdef DEBUG
            /* For debugging, note that we have to reserve space even for
               unused variables if they are ever in scope. However, this is not
               an issue as fgExtendDbgLifetimes() adds an initialization and
               variables in scope will not have a zero ref-cnt.
             */
            if (opts.compDbgCode && !varDsc->lvIsParam && varDsc->lvTracked)
            {
                for (unsigned scopeNum = 0; scopeNum < info.compVarScopesCount; scopeNum++)
                {
                    noway_assert(info.compVarScopes[scopeNum].vsdVarNum != lclNum);
                }
            }
#endif
            /*
              For Debug Code, we have to reserve space even if the variable is never
              in scope. We will also need to initialize it if it is a GC var.
              So we set lvMustInit and artifically bump up the ref-cnt.
             */

            if (opts.compDbgCode && !stkFixedArgInVarArgs && lclNum < info.compLocalsCount)
            {
                needSlot |= true;

                if (lvaTypeIsGC(lclNum))
                {
                    varDsc->lvRefCnt = 1;
                }

                if (!varDsc->lvIsParam)
                {
                    varDsc->lvMustInit = true;
                }
            }

#ifndef LEGACY_BACKEND
            varDsc->lvOnFrame = needSlot;
#endif // !LEGACY_BACKEND
            if (!needSlot)
            {
                /* Clear the lvMustInit flag in case it is set */
                varDsc->lvMustInit = false;

                goto NOT_STK;
            }
        }

#ifndef LEGACY_BACKEND
        if (!varDsc->lvOnFrame)
        {
            goto NOT_STK;
        }
#endif // !LEGACY_BACKEND

    ON_STK:
        /* The variable (or part of it) lives on the stack frame */

        noway_assert((varDsc->lvType != TYP_UNDEF) && (varDsc->lvType != TYP_VOID) && (varDsc->lvType != TYP_UNKNOWN));
#if FEATURE_FIXED_OUT_ARGS
        noway_assert((lclNum == lvaOutgoingArgSpaceVar) || lvaLclSize(lclNum) != 0);
#else  // FEATURE_FIXED_OUT_ARGS
        noway_assert(lvaLclSize(lclNum) != 0);
#endif // FEATURE_FIXED_OUT_ARGS

        varDsc->lvOnFrame = true; // Our prediction is that the final home for this local variable will be in the
                                  // stack frame

    NOT_STK:;
        varDsc->lvFramePointerBased = codeGen->isFramePointerUsed();

#if DOUBLE_ALIGN

        if (codeGen->doDoubleAlign())
        {
            noway_assert(codeGen->isFramePointerUsed() == false);

            /* All arguments are off of EBP with double-aligned frames */

            if (varDsc->lvIsParam && !varDsc->lvIsRegArg)
            {
                varDsc->lvFramePointerBased = true;
            }
        }

#endif

        /* Some basic checks */

        // It must be in a register, on frame, or have zero references.

        noway_assert(varDsc->lvIsInReg() || varDsc->lvOnFrame || varDsc->lvRefCnt == 0);

#ifndef LEGACY_BACKEND
        // We can't have both lvRegister and lvOnFrame for RyuJIT
        noway_assert(!varDsc->lvRegister || !varDsc->lvOnFrame);
#else  // LEGACY_BACKEND

        /* If both lvRegister and lvOnFrame are set, it must be partially enregistered */
        noway_assert(!varDsc->lvRegister || !varDsc->lvOnFrame ||
                     (varDsc->lvType == TYP_LONG && varDsc->lvOtherReg == REG_STK));
#endif // LEGACY_BACKEND

#ifdef DEBUG

        // For varargs functions, there should be no direct references to
        // parameter variables except for 'this' (because these were morphed
        // in the importer) and the 'arglist' parameter (which is not a GC
        // pointer). and the return buffer argument (if we are returning a
        // struct).
        // This is important because we don't want to try to report them
        // to the GC, as the frame offsets in these local varables would
        // not be correct.

        if (varDsc->lvIsParam && raIsVarargsStackArg(lclNum))
        {
            if (!varDsc->lvPromoted && !varDsc->lvIsStructField)
            {
                noway_assert(varDsc->lvRefCnt == 0 && !varDsc->lvRegister && !varDsc->lvOnFrame);
            }
        }
#endif
    }
}

#ifdef LEGACY_BACKEND
void Compiler::rpRecordPrediction()
{
    if (rpBestRecordedPrediction == NULL || rpStkPredict < rpBestRecordedStkPredict)
    {
        if (rpBestRecordedPrediction == NULL)
        {
            rpBestRecordedPrediction =
                reinterpret_cast<VarRegPrediction*>(compGetMemArrayA(lvaCount, sizeof(VarRegPrediction)));
        }
        for (unsigned k = 0; k < lvaCount; k++)
        {
            rpBestRecordedPrediction[k].m_isEnregistered = lvaTable[k].lvRegister;
            rpBestRecordedPrediction[k].m_regNum         = (regNumberSmall)lvaTable[k].GetRegNum();
            rpBestRecordedPrediction[k].m_otherReg       = (regNumberSmall)lvaTable[k].GetOtherReg();
        }
        rpBestRecordedStkPredict = rpStkPredict;
        JITDUMP("Recorded a feasible reg prediction with weighted stack use count %d.\n", rpBestRecordedStkPredict);
    }
}

void Compiler::rpUseRecordedPredictionIfBetter()
{
    JITDUMP("rpStkPredict is %d; previous feasible reg prediction is %d.\n", rpStkPredict,
            rpBestRecordedPrediction != NULL ? rpBestRecordedStkPredict : 0);
    if (rpBestRecordedPrediction != NULL && rpStkPredict > rpBestRecordedStkPredict)
    {
        JITDUMP("Reverting to a previously-recorded feasible reg prediction with weighted stack use count %d.\n",
                rpBestRecordedStkPredict);

        for (unsigned k = 0; k < lvaCount; k++)
        {
            lvaTable[k].lvRegister = rpBestRecordedPrediction[k].m_isEnregistered;
            lvaTable[k].SetRegNum(static_cast<regNumber>(rpBestRecordedPrediction[k].m_regNum));
            lvaTable[k].SetOtherReg(static_cast<regNumber>(rpBestRecordedPrediction[k].m_otherReg));
        }
    }
}
#endif // LEGACY_BACKEND