arm-shrink-wrapping.ll 60.6 KB
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
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc %s -o - -enable-shrink-wrap=true -ifcvt-fn-start=1 -ifcvt-fn-stop=0 -mtriple=armv7-apple-ios \
; RUN:      | FileCheck %s --check-prefix=ARM-ENABLE
; RUN: llc %s -o - -enable-shrink-wrap=false -ifcvt-fn-start=1 -ifcvt-fn-stop=0 -mtriple=armv7-apple-ios \
; RUN:      | FileCheck %s --check-prefix=ARM-DISABLE
; RUN: llc %s -o - -enable-shrink-wrap=true -ifcvt-fn-start=1 -ifcvt-fn-stop=0 -mtriple=thumbv7-apple-ios \
; RUN:      | FileCheck %s --check-prefix=THUMB-ENABLE
; RUN: llc %s -o - -enable-shrink-wrap=false -ifcvt-fn-start=1 -ifcvt-fn-stop=0 -mtriple=thumbv7-apple-ios \
; RUN:      | FileCheck %s --check-prefix=THUMB-DISABLE

;
; Note: Lots of tests use inline asm instead of regular calls.
; This allows to have a better control on what the allocation will do.
; Otherwise, we may have spill right in the entry block, defeating
; shrink-wrapping. Moreover, some of the inline asm statements (nop)
; are here to ensure that the related paths do not end up as critical
; edges.
; Also disable the late if-converter as it makes harder to reason on
; the diffs.

; Initial motivating example: Simple diamond with a call just on one side.
; foo:
;
; Compare the arguments and jump to exit.
; No prologue needed.
; cmp r0, r1
; bge [[EXIT_LABEL:LBB[0-9_]+]]
;
; Prologue code.
; push {r7, lr}
; mov r7, sp
;;
; Compare the arguments and jump to exit.
; After the prologue is set.
; sub sp
; cmp r0, r1
; bge [[EXIT_LABEL:LBB[0-9_]+]]
;
; Store %a in the alloca.
; push {r0}
; str r0, [sp, #-4]
; str r0, [sp]
; Set the alloca address in the second argument.
; mov r1, sp
; Set the first argument to zero.
; mov{{s?}} r0, #0
; bl{{x?}} _doSomething
;
; With shrink-wrapping, epilogue is just after the call.
; mov sp, r7
; add sp, #4
; pop{{(\.w)?}} {r7, lr}
;
; [[EXIT_LABEL]]:
;
; Without shrink-wrapping, epilogue is in the exit block.
; Epilogue code. (What we pop does not matter.)
; mov sp, r7
; add sp,
; pop {r7, pc}
;
; bx lr
define i32 @foo(i32 %a, i32 %b) "frame-pointer"="all" {
; ARM-ENABLE-LABEL: foo:
; ARM-ENABLE:       @ %bb.0:
; ARM-ENABLE-NEXT:    cmp r0, r1
; ARM-ENABLE-NEXT:    bge LBB0_2
; ARM-ENABLE-NEXT:  @ %bb.1: @ %true
; ARM-ENABLE-NEXT:    push {r7, lr}
; ARM-ENABLE-NEXT:    mov r7, sp
; ARM-ENABLE-NEXT:    push {r0}
; ARM-ENABLE-NEXT:    mov r1, sp
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    bl _doSomething
; ARM-ENABLE-NEXT:    mov sp, r7
; ARM-ENABLE-NEXT:    pop {r7, lr}
; ARM-ENABLE-NEXT:  LBB0_2: @ %false
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: foo:
; ARM-DISABLE:       @ %bb.0:
; ARM-DISABLE-NEXT:    push {r7, lr}
; ARM-DISABLE-NEXT:    mov r7, sp
; ARM-DISABLE-NEXT:    sub sp, sp, #4
; ARM-DISABLE-NEXT:    cmp r0, r1
; ARM-DISABLE-NEXT:    bge LBB0_2
; ARM-DISABLE-NEXT:  @ %bb.1: @ %true
; ARM-DISABLE-NEXT:    str r0, [sp]
; ARM-DISABLE-NEXT:    mov r1, sp
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    bl _doSomething
; ARM-DISABLE-NEXT:  LBB0_2: @ %false
; ARM-DISABLE-NEXT:    mov sp, r7
; ARM-DISABLE-NEXT:    pop {r7, pc}
;
; THUMB-ENABLE-LABEL: foo:
; THUMB-ENABLE:       @ %bb.0:
; THUMB-ENABLE-NEXT:    cmp r0, r1
; THUMB-ENABLE-NEXT:    bge LBB0_2
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %true
; THUMB-ENABLE-NEXT:    push {r7, lr}
; THUMB-ENABLE-NEXT:    mov r7, sp
; THUMB-ENABLE-NEXT:    str r0, [sp, #-4]!
; THUMB-ENABLE-NEXT:    mov r1, sp
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    bl _doSomething
; THUMB-ENABLE-NEXT:    add sp, #4
; THUMB-ENABLE-NEXT:    pop.w {r7, lr}
; THUMB-ENABLE-NEXT:  LBB0_2: @ %false
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: foo:
; THUMB-DISABLE:       @ %bb.0:
; THUMB-DISABLE-NEXT:    push {r7, lr}
; THUMB-DISABLE-NEXT:    mov r7, sp
; THUMB-DISABLE-NEXT:    sub sp, #4
; THUMB-DISABLE-NEXT:    cmp r0, r1
; THUMB-DISABLE-NEXT:    bge LBB0_2
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %true
; THUMB-DISABLE-NEXT:    str r0, [sp]
; THUMB-DISABLE-NEXT:    mov r1, sp
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    bl _doSomething
; THUMB-DISABLE-NEXT:  LBB0_2: @ %false
; THUMB-DISABLE-NEXT:    add sp, #4
; THUMB-DISABLE-NEXT:    pop {r7, pc}
  %tmp = alloca i32, align 4
  %tmp2 = icmp slt i32 %a, %b
  br i1 %tmp2, label %true, label %false

true:
  store i32 %a, i32* %tmp, align 4
  %tmp4 = call i32 @doSomething(i32 0, i32* %tmp)
  br label %false

false:
  %tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ]
  ret i32 %tmp.0
}

; Function Attrs: optsize
declare i32 @doSomething(i32, i32*)


; Check that we do not perform the restore inside the loop whereas the save
; is outside.
; freqSaveAndRestoreOutsideLoop:
;
; Shrink-wrapping allows to skip the prologue in the else case.
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; Prologue code.
; Make sure we save the CSR used in the inline asm: r4.
; push {r4, r7, lr}
; add r7, sp, #4
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; SUM is in r0 because it is coalesced with the second
; argument on the else path.
; mov{{s?}} [[SUM:r0]], #0
; mov{{s?}} [[IV:r[0-9]+]], #10
;
; Next BB.
; [[LOOP:LBB[0-9_]+]]: @ %for.body
; mov{{(\.w)?}} [[TMP:r[0-9]+]], #1
; add [[SUM]], [[TMP]], [[SUM]]
; add [[SUM]], [[TMP]]
; subs [[IV]], [[IV]], #1
; subs [[IV]], #1
; bne [[LOOP]]
;
; Next BB.
; SUM << 3.
; lsl{{s?}} [[SUM]], [[SUM]], #3
; pop {r4, r7, pc}
;
; Duplicated epilogue.
; pop {r4, r7, pc}
;
; [[ELSE_LABEL]]: @ %if.else
; Shift second argument by one and store into returned register.
; lsl{{s?}} r0, r1, #1
; pop {r4, r7, pc}
;
; bx lr
define i32 @freqSaveAndRestoreOutsideLoop(i32 %cond, i32 %N) "frame-pointer"="all" {
; ARM-ENABLE-LABEL: freqSaveAndRestoreOutsideLoop:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    beq LBB1_4
; ARM-ENABLE-NEXT:  @ %bb.1: @ %for.preheader
; ARM-ENABLE-NEXT:    push {r4, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #4
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    mov r1, #10
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:  LBB1_2: @ %for.body
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    mov r2, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    add r0, r2, r0
; ARM-ENABLE-NEXT:    subs r1, r1, #1
; ARM-ENABLE-NEXT:    bne LBB1_2
; ARM-ENABLE-NEXT:  @ %bb.3: @ %for.end
; ARM-ENABLE-NEXT:    lsl r0, r0, #3
; ARM-ENABLE-NEXT:    pop {r4, r7, pc}
; ARM-ENABLE-NEXT:  LBB1_4: @ %if.else
; ARM-ENABLE-NEXT:    lsl r0, r1, #1
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: freqSaveAndRestoreOutsideLoop:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #4
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    beq LBB1_4
; ARM-DISABLE-NEXT:  @ %bb.1: @ %for.preheader
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    mov r1, #10
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:  LBB1_2: @ %for.body
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    mov r2, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    add r0, r2, r0
; ARM-DISABLE-NEXT:    subs r1, r1, #1
; ARM-DISABLE-NEXT:    bne LBB1_2
; ARM-DISABLE-NEXT:  @ %bb.3: @ %for.end
; ARM-DISABLE-NEXT:    lsl r0, r0, #3
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
; ARM-DISABLE-NEXT:  LBB1_4: @ %if.else
; ARM-DISABLE-NEXT:    lsl r0, r1, #1
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
;
; THUMB-ENABLE-LABEL: freqSaveAndRestoreOutsideLoop:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    cbz r0, LBB1_4
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %for.preheader
; THUMB-ENABLE-NEXT:    push {r4, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #4
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    movs r1, #10
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:  LBB1_2: @ %for.body
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    mov.w r2, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    add r0, r2
; THUMB-ENABLE-NEXT:    subs r1, #1
; THUMB-ENABLE-NEXT:    bne LBB1_2
; THUMB-ENABLE-NEXT:  @ %bb.3: @ %for.end
; THUMB-ENABLE-NEXT:    lsls r0, r0, #3
; THUMB-ENABLE-NEXT:    pop {r4, r7, pc}
; THUMB-ENABLE-NEXT:  LBB1_4: @ %if.else
; THUMB-ENABLE-NEXT:    lsls r0, r1, #1
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: freqSaveAndRestoreOutsideLoop:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #4
; THUMB-DISABLE-NEXT:    cbz r0, LBB1_4
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %for.preheader
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    movs r1, #10
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:  LBB1_2: @ %for.body
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    mov.w r2, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    add r0, r2
; THUMB-DISABLE-NEXT:    subs r1, #1
; THUMB-DISABLE-NEXT:    bne LBB1_2
; THUMB-DISABLE-NEXT:  @ %bb.3: @ %for.end
; THUMB-DISABLE-NEXT:    lsls r0, r0, #3
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
; THUMB-DISABLE-NEXT:  LBB1_4: @ %if.else
; THUMB-DISABLE-NEXT:    lsls r0, r1, #1
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
entry:
  %tobool = icmp eq i32 %cond, 0
  br i1 %tobool, label %if.else, label %for.preheader

for.preheader:
  tail call void asm "nop", ""()
  br label %for.body

for.body:                                         ; preds = %entry, %for.body
  %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ]
  %sum.04 = phi i32 [ %add, %for.body ], [ 0, %for.preheader ]
  %call = tail call i32 asm sideeffect "mov $0, #1", "=r,~{r4}"()
  %add = add nsw i32 %call, %sum.04
  %inc = add nuw nsw i32 %i.05, 1
  %exitcond = icmp eq i32 %inc, 10
  br i1 %exitcond, label %for.end, label %for.body

for.end:                                          ; preds = %for.body
  %shl = shl i32 %add, 3
  br label %if.end

if.else:                                          ; preds = %entry
  %mul = shl nsw i32 %N, 1
  br label %if.end

if.end:                                           ; preds = %if.else, %for.end
  %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ]
  ret i32 %sum.1
}

declare i32 @something(...)

; Check that we do not perform the shrink-wrapping inside the loop even
; though that would be legal. The cost model must prevent that.
; freqSaveAndRestoreOutsideLoop2:
; Prologue code.
; Make sure we save the CSR used in the inline asm: r4.
; push {r4
; mov{{s?}} [[SUM:r0]], #0
; mov{{s?}} [[IV:r[0-9]+]], #10
; nop
; Next BB.
; [[LOOP_LABEL:LBB[0-9_]+]]: @ %for.body
; mov{{(\.w)?}} [[TMP:r[0-9]+]], #1
; add [[SUM]], [[TMP]], [[SUM]]
; add [[SUM]], [[TMP]]
; subs [[IV]], [[IV]], #1
; subs [[IV]], #1
; bne [[LOOP_LABEL]]
; Next BB.
; @ %for.exit
; nop
; pop {r4
define i32 @freqSaveAndRestoreOutsideLoop2(i32 %cond) "frame-pointer"="all" {
; ARM-LABEL: freqSaveAndRestoreOutsideLoop2:
; ARM:       @ %bb.0: @ %entry
; ARM-NEXT:    push {r4, r7, lr}
; ARM-NEXT:    add r7, sp, #4
; ARM-NEXT:    mov r0, #0
; ARM-NEXT:    mov r1, #10
; ARM-NEXT:    @ InlineAsm Start
; ARM-NEXT:    nop
; ARM-NEXT:    @ InlineAsm End
; ARM-NEXT:  LBB2_1: @ %for.body
; ARM-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-NEXT:    @ InlineAsm Start
; ARM-NEXT:    mov r2, #1
; ARM-NEXT:    @ InlineAsm End
; ARM-NEXT:    add r0, r2, r0
; ARM-NEXT:    subs r1, r1, #1
; ARM-NEXT:    bne LBB2_1
; ARM-NEXT:  @ %bb.2: @ %for.exit
; ARM-NEXT:    @ InlineAsm Start
; ARM-NEXT:    nop
; ARM-NEXT:    @ InlineAsm End
; ARM-NEXT:    pop {r4, r7, pc}
;
; THUMB-LABEL: freqSaveAndRestoreOutsideLoop2:
; THUMB:       @ %bb.0: @ %entry
; THUMB-NEXT:    push {r4, r7, lr}
; THUMB-NEXT:    add r7, sp, #4
; THUMB-NEXT:    movs r0, #0
; THUMB-NEXT:    movs r1, #10
; THUMB-NEXT:    @ InlineAsm Start
; THUMB-NEXT:    nop
; THUMB-NEXT:    @ InlineAsm End
; THUMB-NEXT:  LBB2_1: @ %for.body
; THUMB-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-NEXT:    @ InlineAsm Start
; THUMB-NEXT:    mov.w r2, #1
; THUMB-NEXT:    @ InlineAsm End
; THUMB-NEXT:    add r0, r2
; THUMB-NEXT:    subs r1, #1
; THUMB-NEXT:    bne LBB2_1
; THUMB-NEXT:  @ %bb.2: @ %for.exit
; THUMB-NEXT:    @ InlineAsm Start
; THUMB-NEXT:    nop
; THUMB-NEXT:    @ InlineAsm End
; THUMB-NEXT:    pop {r4, r7, pc}
; ARM-ENABLE-LABEL: freqSaveAndRestoreOutsideLoop2:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    push {r4, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #4
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    mov r1, #10
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:  LBB2_1: @ %for.body
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    mov r2, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    add r0, r2, r0
; ARM-ENABLE-NEXT:    subs r1, r1, #1
; ARM-ENABLE-NEXT:    bne LBB2_1
; ARM-ENABLE-NEXT:  @ %bb.2: @ %for.exit
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    pop {r4, r7, pc}
;
; ARM-DISABLE-LABEL: freqSaveAndRestoreOutsideLoop2:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #4
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    mov r1, #10
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:  LBB2_1: @ %for.body
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    mov r2, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    add r0, r2, r0
; ARM-DISABLE-NEXT:    subs r1, r1, #1
; ARM-DISABLE-NEXT:    bne LBB2_1
; ARM-DISABLE-NEXT:  @ %bb.2: @ %for.exit
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
;
; THUMB-ENABLE-LABEL: freqSaveAndRestoreOutsideLoop2:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    push {r4, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #4
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    movs r1, #10
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:  LBB2_1: @ %for.body
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    mov.w r2, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    add r0, r2
; THUMB-ENABLE-NEXT:    subs r1, #1
; THUMB-ENABLE-NEXT:    bne LBB2_1
; THUMB-ENABLE-NEXT:  @ %bb.2: @ %for.exit
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    pop {r4, r7, pc}
;
; THUMB-DISABLE-LABEL: freqSaveAndRestoreOutsideLoop2:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #4
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    movs r1, #10
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:  LBB2_1: @ %for.body
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    mov.w r2, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    add r0, r2
; THUMB-DISABLE-NEXT:    subs r1, #1
; THUMB-DISABLE-NEXT:    bne LBB2_1
; THUMB-DISABLE-NEXT:  @ %bb.2: @ %for.exit
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
entry:
  br label %for.preheader

for.preheader:
  tail call void asm "nop", ""()
  br label %for.body

for.body:                                         ; preds = %for.body, %entry
  %i.04 = phi i32 [ 0, %for.preheader ], [ %inc, %for.body ]
  %sum.03 = phi i32 [ 0, %for.preheader ], [ %add, %for.body ]
  %call = tail call i32 asm sideeffect "mov $0, #1", "=r,~{r4}"()
  %add = add nsw i32 %call, %sum.03
  %inc = add nuw nsw i32 %i.04, 1
  %exitcond = icmp eq i32 %inc, 10
  br i1 %exitcond, label %for.exit, label %for.body

for.exit:
  tail call void asm "nop", ""()
  br label %for.end

for.end:                                          ; preds = %for.body
  ret i32 %add
}

; Check with a more complex case that we do not have save within the loop and
; restore outside.
; loopInfoSaveOutsideLoop:
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; Prologue code.
; Make sure we save the CSR used in the inline asm: r4.
; push {r4, r7, lr}
; add r7, sp, #4
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; SUM is in r0 because it is coalesced with the second
; argument on the else path.
; mov{{s?}} [[SUM:r0]], #0
; mov{{s?}} [[IV:r[0-9]+]], #10
;
; Next BB.
; [[LOOP:LBB[0-9_]+]]: @ %for.body
; mov{{(\.w)?}} [[TMP:r[0-9]+]], #1
; add [[SUM]], [[TMP]], [[SUM]]
; add [[SUM]], [[TMP]]
; subs [[IV]], [[IV]], #1
; subs [[IV]], #1
; bne [[LOOP]]
;
; Next BB.
; SUM << 3.
; lsl{{s?}} [[SUM]], [[SUM]], #3
; pop {r4, r7, pc}
;
; Duplicated epilogue.
; pop {r4, r7, pc}
;
; [[ELSE_LABEL]]: @ %if.else
; Shift second argument by one and store into returned register.
; lsl{{s?}} r0, r1, #1
; pop {r4, r7, pc}
;
; bx lr
define i32 @loopInfoSaveOutsideLoop(i32 %cond, i32 %N) "frame-pointer"="all" {
; ARM-ENABLE-LABEL: loopInfoSaveOutsideLoop:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    beq LBB3_4
; ARM-ENABLE-NEXT:  @ %bb.1: @ %for.preheader
; ARM-ENABLE-NEXT:    push {r4, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #4
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    mov r1, #10
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:  LBB3_2: @ %for.body
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    mov r2, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    add r0, r2, r0
; ARM-ENABLE-NEXT:    subs r1, r1, #1
; ARM-ENABLE-NEXT:    bne LBB3_2
; ARM-ENABLE-NEXT:  @ %bb.3: @ %for.end
; ARM-ENABLE-NEXT:    lsl r0, r0, #3
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    pop {r4, r7, pc}
; ARM-ENABLE-NEXT:  LBB3_4: @ %if.else
; ARM-ENABLE-NEXT:    lsl r0, r1, #1
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: loopInfoSaveOutsideLoop:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #4
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    beq LBB3_4
; ARM-DISABLE-NEXT:  @ %bb.1: @ %for.preheader
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    mov r1, #10
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:  LBB3_2: @ %for.body
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    mov r2, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    add r0, r2, r0
; ARM-DISABLE-NEXT:    subs r1, r1, #1
; ARM-DISABLE-NEXT:    bne LBB3_2
; ARM-DISABLE-NEXT:  @ %bb.3: @ %for.end
; ARM-DISABLE-NEXT:    lsl r0, r0, #3
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
; ARM-DISABLE-NEXT:  LBB3_4: @ %if.else
; ARM-DISABLE-NEXT:    lsl r0, r1, #1
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
;
; THUMB-ENABLE-LABEL: loopInfoSaveOutsideLoop:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    cbz r0, LBB3_4
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %for.preheader
; THUMB-ENABLE-NEXT:    push {r4, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #4
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    movs r1, #10
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:  LBB3_2: @ %for.body
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    mov.w r2, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    add r0, r2
; THUMB-ENABLE-NEXT:    subs r1, #1
; THUMB-ENABLE-NEXT:    bne LBB3_2
; THUMB-ENABLE-NEXT:  @ %bb.3: @ %for.end
; THUMB-ENABLE-NEXT:    lsls r0, r0, #3
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    pop {r4, r7, pc}
; THUMB-ENABLE-NEXT:  LBB3_4: @ %if.else
; THUMB-ENABLE-NEXT:    lsls r0, r1, #1
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: loopInfoSaveOutsideLoop:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #4
; THUMB-DISABLE-NEXT:    cbz r0, LBB3_4
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %for.preheader
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    movs r1, #10
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:  LBB3_2: @ %for.body
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    mov.w r2, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    add r0, r2
; THUMB-DISABLE-NEXT:    subs r1, #1
; THUMB-DISABLE-NEXT:    bne LBB3_2
; THUMB-DISABLE-NEXT:  @ %bb.3: @ %for.end
; THUMB-DISABLE-NEXT:    lsls r0, r0, #3
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
; THUMB-DISABLE-NEXT:  LBB3_4: @ %if.else
; THUMB-DISABLE-NEXT:    lsls r0, r1, #1
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
entry:
  %tobool = icmp eq i32 %cond, 0
  br i1 %tobool, label %if.else, label %for.preheader

for.preheader:
  tail call void asm "nop", ""()
  br label %for.body

for.body:                                         ; preds = %entry, %for.body
  %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ]
  %sum.04 = phi i32 [ %add, %for.body ], [ 0, %for.preheader ]
  %call = tail call i32 asm sideeffect "mov $0, #1", "=r,~{r4}"()
  %add = add nsw i32 %call, %sum.04
  %inc = add nuw nsw i32 %i.05, 1
  %exitcond = icmp eq i32 %inc, 10
  br i1 %exitcond, label %for.end, label %for.body

for.end:                                          ; preds = %for.body
  tail call void asm "nop", "~{r4}"()
  %shl = shl i32 %add, 3
  br label %if.end

if.else:                                          ; preds = %entry
  %mul = shl nsw i32 %N, 1
  br label %if.end

if.end:                                           ; preds = %if.else, %for.end
  %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ]
  ret i32 %sum.1
}

declare void @somethingElse(...)

; Check with a more complex case that we do not have restore within the loop and
; save outside.
; loopInfoRestoreOutsideLoop:
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; Prologue code.
; Make sure we save the CSR used in the inline asm: r4.
; push {r4, r7, lr}
; add r7, sp, #4
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; SUM is in r0 because it is coalesced with the second
; argument on the else path.
; mov{{s?}} [[SUM:r0]], #0
; mov{{s?}} [[IV:r[0-9]+]], #10
;
; Next BB.
; [[LOOP:LBB[0-9_]+]]: @ %for.body
; mov{{(\.w)?}} [[TMP:r[0-9]+]], #1
; add [[SUM]], [[TMP]], [[SUM]]
; add [[SUM]], [[TMP]]
; subs [[IV]], [[IV]], #1
; subs [[IV]], #1
; bne [[LOOP]]
;
; Next BB.
; SUM << 3.
; lsl{{s?}} [[SUM]], [[SUM]], #3
; pop {r4, r7, pc}
;
; Duplicated epilogue.
; pop {r4, r7, pc}
;
; [[ELSE_LABEL]]: @ %if.else
; Shift second argument by one and store into returned register.
; lsl{{s?}} r0, r1, #1
; pop {r4, r7, pc}
;
; bx lr
define i32 @loopInfoRestoreOutsideLoop(i32 %cond, i32 %N) "frame-pointer"="all" nounwind {
; ARM-ENABLE-LABEL: loopInfoRestoreOutsideLoop:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    beq LBB4_4
; ARM-ENABLE-NEXT:  @ %bb.1: @ %if.then
; ARM-ENABLE-NEXT:    push {r4, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #4
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    mov r1, #10
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:  LBB4_2: @ %for.body
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    mov r2, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    add r0, r2, r0
; ARM-ENABLE-NEXT:    subs r1, r1, #1
; ARM-ENABLE-NEXT:    bne LBB4_2
; ARM-ENABLE-NEXT:  @ %bb.3: @ %for.end
; ARM-ENABLE-NEXT:    lsl r0, r0, #3
; ARM-ENABLE-NEXT:    pop {r4, r7, pc}
; ARM-ENABLE-NEXT:  LBB4_4: @ %if.else
; ARM-ENABLE-NEXT:    lsl r0, r1, #1
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: loopInfoRestoreOutsideLoop:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #4
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    beq LBB4_4
; ARM-DISABLE-NEXT:  @ %bb.1: @ %if.then
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    mov r1, #10
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:  LBB4_2: @ %for.body
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    mov r2, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    add r0, r2, r0
; ARM-DISABLE-NEXT:    subs r1, r1, #1
; ARM-DISABLE-NEXT:    bne LBB4_2
; ARM-DISABLE-NEXT:  @ %bb.3: @ %for.end
; ARM-DISABLE-NEXT:    lsl r0, r0, #3
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
; ARM-DISABLE-NEXT:  LBB4_4: @ %if.else
; ARM-DISABLE-NEXT:    lsl r0, r1, #1
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
;
; THUMB-ENABLE-LABEL: loopInfoRestoreOutsideLoop:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    cbz r0, LBB4_4
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %if.then
; THUMB-ENABLE-NEXT:    push {r4, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #4
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    movs r1, #10
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:  LBB4_2: @ %for.body
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    mov.w r2, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    add r0, r2
; THUMB-ENABLE-NEXT:    subs r1, #1
; THUMB-ENABLE-NEXT:    bne LBB4_2
; THUMB-ENABLE-NEXT:  @ %bb.3: @ %for.end
; THUMB-ENABLE-NEXT:    lsls r0, r0, #3
; THUMB-ENABLE-NEXT:    pop {r4, r7, pc}
; THUMB-ENABLE-NEXT:  LBB4_4: @ %if.else
; THUMB-ENABLE-NEXT:    lsls r0, r1, #1
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: loopInfoRestoreOutsideLoop:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #4
; THUMB-DISABLE-NEXT:    cbz r0, LBB4_4
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %if.then
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    movs r1, #10
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:  LBB4_2: @ %for.body
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    mov.w r2, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    add r0, r2
; THUMB-DISABLE-NEXT:    subs r1, #1
; THUMB-DISABLE-NEXT:    bne LBB4_2
; THUMB-DISABLE-NEXT:  @ %bb.3: @ %for.end
; THUMB-DISABLE-NEXT:    lsls r0, r0, #3
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
; THUMB-DISABLE-NEXT:  LBB4_4: @ %if.else
; THUMB-DISABLE-NEXT:    lsls r0, r1, #1
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
entry:
  %tobool = icmp eq i32 %cond, 0
  br i1 %tobool, label %if.else, label %if.then

if.then:                                          ; preds = %entry
  tail call void asm "nop", "~{r4}"()
  br label %for.body

for.body:                                         ; preds = %for.body, %if.then
  %i.05 = phi i32 [ 0, %if.then ], [ %inc, %for.body ]
  %sum.04 = phi i32 [ 0, %if.then ], [ %add, %for.body ]
  %call = tail call i32 asm sideeffect "mov $0, #1", "=r,~{r4}"()
  %add = add nsw i32 %call, %sum.04
  %inc = add nuw nsw i32 %i.05, 1
  %exitcond = icmp eq i32 %inc, 10
  br i1 %exitcond, label %for.end, label %for.body

for.end:                                          ; preds = %for.body
  %shl = shl i32 %add, 3
  br label %if.end

if.else:                                          ; preds = %entry
  %mul = shl nsw i32 %N, 1
  br label %if.end

if.end:                                           ; preds = %if.else, %for.end
  %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ]
  ret i32 %sum.1
}

; Check that we handle function with no frame information correctly.
; emptyFrame:
; @ %entry
; mov{{s?}} r0, #0
; bx lr
define i32 @emptyFrame() {
; ARM-LABEL: emptyFrame:
; ARM:       @ %bb.0: @ %entry
; ARM-NEXT:    mov r0, #0
; ARM-NEXT:    bx lr
;
; THUMB-LABEL: emptyFrame:
; THUMB:       @ %bb.0: @ %entry
; THUMB-NEXT:    movs r0, #0
; THUMB-NEXT:    bx lr
; ARM-ENABLE-LABEL: emptyFrame:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: emptyFrame:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    bx lr
;
; THUMB-ENABLE-LABEL: emptyFrame:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: emptyFrame:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    bx lr
entry:
  ret i32 0
}

; Check that we handle inline asm correctly.
; inlineAsm:
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; Prologue code.
; Make sure we save the CSR used in the inline asm: r4.
; push {r4, r7, lr}
; add r7, sp, #4
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; mov{{s?}} [[IV:r[0-9]+]], #10
;
; Next BB.
; [[LOOP:LBB[0-9_]+]]: @ %for.body
; subs [[IV]], [[IV]], #1
; subs [[IV]], #1
; add{{(\.w)?}} r4, r4, #1
; bne [[LOOP]]
;
; Next BB.
; mov{{s?}} r0, #0
;
; Duplicated epilogue.
; pop {r4, r7, pc}
;
; [[ELSE_LABEL]]: @ %if.else
; Shift second argument by one and store into returned register.
; lsl{{s?}} r0, r1, #1
; pop {r4, r7, pc}
;
; bx lr
define i32 @inlineAsm(i32 %cond, i32 %N) "frame-pointer"="all" {
; ARM-ENABLE-LABEL: inlineAsm:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    beq LBB6_4
; ARM-ENABLE-NEXT:  @ %bb.1: @ %for.preheader
; ARM-ENABLE-NEXT:    push {r4, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #4
; ARM-ENABLE-NEXT:    mov r0, #10
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:  LBB6_2: @ %for.body
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    subs r0, r0, #1
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    add r4, r4, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    bne LBB6_2
; ARM-ENABLE-NEXT:  @ %bb.3: @ %for.exit
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    nop
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    pop {r4, r7, pc}
; ARM-ENABLE-NEXT:  LBB6_4: @ %if.else
; ARM-ENABLE-NEXT:    lsl r0, r1, #1
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: inlineAsm:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #4
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    beq LBB6_4
; ARM-DISABLE-NEXT:  @ %bb.1: @ %for.preheader
; ARM-DISABLE-NEXT:    mov r0, #10
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:  LBB6_2: @ %for.body
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    subs r0, r0, #1
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    add r4, r4, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    bne LBB6_2
; ARM-DISABLE-NEXT:  @ %bb.3: @ %for.exit
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    nop
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
; ARM-DISABLE-NEXT:  LBB6_4: @ %if.else
; ARM-DISABLE-NEXT:    lsl r0, r1, #1
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
;
; THUMB-ENABLE-LABEL: inlineAsm:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    cbz r0, LBB6_4
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %for.preheader
; THUMB-ENABLE-NEXT:    push {r4, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #4
; THUMB-ENABLE-NEXT:    movs r0, #10
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:  LBB6_2: @ %for.body
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    subs r0, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    add.w r4, r4, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    bne LBB6_2
; THUMB-ENABLE-NEXT:  @ %bb.3: @ %for.exit
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    nop
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    pop {r4, r7, pc}
; THUMB-ENABLE-NEXT:  LBB6_4: @ %if.else
; THUMB-ENABLE-NEXT:    lsls r0, r1, #1
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: inlineAsm:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #4
; THUMB-DISABLE-NEXT:    cbz r0, LBB6_4
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %for.preheader
; THUMB-DISABLE-NEXT:    movs r0, #10
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:  LBB6_2: @ %for.body
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    subs r0, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    add.w r4, r4, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    bne LBB6_2
; THUMB-DISABLE-NEXT:  @ %bb.3: @ %for.exit
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    nop
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
; THUMB-DISABLE-NEXT:  LBB6_4: @ %if.else
; THUMB-DISABLE-NEXT:    lsls r0, r1, #1
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
entry:
  %tobool = icmp eq i32 %cond, 0
  br i1 %tobool, label %if.else, label %for.preheader

for.preheader:
  tail call void asm "nop", ""()
  br label %for.body

for.body:                                         ; preds = %entry, %for.body
  %i.03 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ]
  tail call void asm sideeffect "add r4, #1", "~{r4}"()
  %inc = add nuw nsw i32 %i.03, 1
  %exitcond = icmp eq i32 %inc, 10
  br i1 %exitcond, label %for.exit, label %for.body

for.exit:
  tail call void asm "nop", ""()
  br label %if.end

if.else:                                          ; preds = %entry
  %mul = shl nsw i32 %N, 1
  br label %if.end

if.end:                                           ; preds = %for.body, %if.else
  %sum.0 = phi i32 [ %mul, %if.else ], [ 0, %for.exit ]
  ret i32 %sum.0
}

; Check that we handle calls to variadic functions correctly.
; callVariadicFunc:
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; Prologue code.
; push {r7, lr}
; mov r7, sp
; sub sp, {{(sp, )?}}#12
;
; cmp r0, #0
; beq [[ELSE_LABEL:LBB[0-9_]+]]
; cbz r0, [[ELSE_LABEL:LBB[0-9_]+]]
;
; Setup of the varags.
; mov r0, r1
; mov r2, r1
; mov r3, r1
; str r1, [sp]
; str r1, [sp, #4]
; strd r1, r1, [sp]
; str r1, [sp, #8]
; bl{{x?}} _someVariadicFunc
; lsl{{s?}} r0, r0, #3
; mov sp, r7
; add sp, #12
; pop {r7, pc}
;
; [[ELSE_LABEL]]: @ %if.else
; Shift second argument by one and store into returned register.
; lsl{{s?}} r0, r1, #1
;
; Epilogue code.
; bx lr
;
; mov sp, r7
; add sp, #12
; pop {r7, pc}
define i32 @callVariadicFunc(i32 %cond, i32 %N) "frame-pointer"="all" {
; ARM-ENABLE-LABEL: callVariadicFunc:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    beq LBB7_2
; ARM-ENABLE-NEXT:  @ %bb.1: @ %if.then
; ARM-ENABLE-NEXT:    push {r7, lr}
; ARM-ENABLE-NEXT:    mov r7, sp
; ARM-ENABLE-NEXT:    sub sp, sp, #12
; ARM-ENABLE-NEXT:    mov r0, r1
; ARM-ENABLE-NEXT:    mov r2, r1
; ARM-ENABLE-NEXT:    mov r3, r1
; ARM-ENABLE-NEXT:    str r1, [sp]
; ARM-ENABLE-NEXT:    str r1, [sp, #4]
; ARM-ENABLE-NEXT:    str r1, [sp, #8]
; ARM-ENABLE-NEXT:    bl _someVariadicFunc
; ARM-ENABLE-NEXT:    lsl r0, r0, #3
; ARM-ENABLE-NEXT:    mov sp, r7
; ARM-ENABLE-NEXT:    pop {r7, pc}
; ARM-ENABLE-NEXT:  LBB7_2: @ %if.else
; ARM-ENABLE-NEXT:    lsl r0, r1, #1
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: callVariadicFunc:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r7, lr}
; ARM-DISABLE-NEXT:    mov r7, sp
; ARM-DISABLE-NEXT:    sub sp, sp, #12
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    beq LBB7_2
; ARM-DISABLE-NEXT:  @ %bb.1: @ %if.then
; ARM-DISABLE-NEXT:    mov r0, r1
; ARM-DISABLE-NEXT:    mov r2, r1
; ARM-DISABLE-NEXT:    mov r3, r1
; ARM-DISABLE-NEXT:    str r1, [sp]
; ARM-DISABLE-NEXT:    str r1, [sp, #4]
; ARM-DISABLE-NEXT:    str r1, [sp, #8]
; ARM-DISABLE-NEXT:    bl _someVariadicFunc
; ARM-DISABLE-NEXT:    lsl r0, r0, #3
; ARM-DISABLE-NEXT:    mov sp, r7
; ARM-DISABLE-NEXT:    pop {r7, pc}
; ARM-DISABLE-NEXT:  LBB7_2: @ %if.else
; ARM-DISABLE-NEXT:    lsl r0, r1, #1
; ARM-DISABLE-NEXT:    mov sp, r7
; ARM-DISABLE-NEXT:    pop {r7, pc}
;
; THUMB-ENABLE-LABEL: callVariadicFunc:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    cbz r0, LBB7_2
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %if.then
; THUMB-ENABLE-NEXT:    push {r7, lr}
; THUMB-ENABLE-NEXT:    mov r7, sp
; THUMB-ENABLE-NEXT:    sub sp, #12
; THUMB-ENABLE-NEXT:    mov r0, r1
; THUMB-ENABLE-NEXT:    mov r2, r1
; THUMB-ENABLE-NEXT:    mov r3, r1
; THUMB-ENABLE-NEXT:    strd r1, r1, [sp]
; THUMB-ENABLE-NEXT:    str r1, [sp, #8]
; THUMB-ENABLE-NEXT:    bl _someVariadicFunc
; THUMB-ENABLE-NEXT:    lsls r0, r0, #3
; THUMB-ENABLE-NEXT:    add sp, #12
; THUMB-ENABLE-NEXT:    pop {r7, pc}
; THUMB-ENABLE-NEXT:  LBB7_2: @ %if.else
; THUMB-ENABLE-NEXT:    lsls r0, r1, #1
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: callVariadicFunc:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r7, lr}
; THUMB-DISABLE-NEXT:    mov r7, sp
; THUMB-DISABLE-NEXT:    sub sp, #12
; THUMB-DISABLE-NEXT:    cbz r0, LBB7_2
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %if.then
; THUMB-DISABLE-NEXT:    mov r0, r1
; THUMB-DISABLE-NEXT:    mov r2, r1
; THUMB-DISABLE-NEXT:    mov r3, r1
; THUMB-DISABLE-NEXT:    strd r1, r1, [sp]
; THUMB-DISABLE-NEXT:    str r1, [sp, #8]
; THUMB-DISABLE-NEXT:    bl _someVariadicFunc
; THUMB-DISABLE-NEXT:    lsls r0, r0, #3
; THUMB-DISABLE-NEXT:    add sp, #12
; THUMB-DISABLE-NEXT:    pop {r7, pc}
; THUMB-DISABLE-NEXT:  LBB7_2: @ %if.else
; THUMB-DISABLE-NEXT:    lsls r0, r1, #1
; THUMB-DISABLE-NEXT:    add sp, #12
; THUMB-DISABLE-NEXT:    pop {r7, pc}
entry:
  %tobool = icmp eq i32 %cond, 0
  br i1 %tobool, label %if.else, label %if.then

if.then:                                          ; preds = %entry
  %call = tail call i32 (i32, ...) @someVariadicFunc(i32 %N, i32 %N, i32 %N, i32 %N, i32 %N, i32 %N, i32 %N)
  %shl = shl i32 %call, 3
  br label %if.end

if.else:                                          ; preds = %entry
  %mul = shl nsw i32 %N, 1
  br label %if.end

if.end:                                           ; preds = %if.else, %if.then
  %sum.0 = phi i32 [ %shl, %if.then ], [ %mul, %if.else ]
  ret i32 %sum.0
}

declare i32 @someVariadicFunc(i32, ...)

; Make sure we do not insert unreachable code after noreturn function.
; Although this is not incorrect to insert such code, it is useless
; and it hurts the binary size.
;
; noreturn:
; push
; cmp r0, #0
; cmp r0, #0
; bne [[ABORT:LBB[0-9_]+]]
; bne [[ABORT:LBB[0-9_]+]]
; cbnz r0,  [[ABORT:LBB[0-9_]+]]
; cbnz r0,  [[ABORT:LBB[0-9_]+]]

;
; mov{{s?}} r0, #42
;
; bx lr
;
; pop
;;
; [[ABORT]]: @ %if.abort
;
; push
;
; bl{{x?}} _abort
; pop
define i32 @noreturn(i8 signext %bad_thing) "frame-pointer"="all" {
; ARM-ENABLE-LABEL: noreturn:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    bne LBB8_2
; ARM-ENABLE-NEXT:  @ %bb.1: @ %if.end
; ARM-ENABLE-NEXT:    mov r0, #42
; ARM-ENABLE-NEXT:    bx lr
; ARM-ENABLE-NEXT:  LBB8_2: @ %if.abort
; ARM-ENABLE-NEXT:    push {r4, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #4
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    mov r0, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    bl _abort
;
; ARM-DISABLE-LABEL: noreturn:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #4
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    bne LBB8_2
; ARM-DISABLE-NEXT:  @ %bb.1: @ %if.end
; ARM-DISABLE-NEXT:    mov r0, #42
; ARM-DISABLE-NEXT:    pop {r4, r7, pc}
; ARM-DISABLE-NEXT:  LBB8_2: @ %if.abort
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    mov r0, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    bl _abort
;
; THUMB-ENABLE-LABEL: noreturn:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    cbnz r0, LBB8_2
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %if.end
; THUMB-ENABLE-NEXT:    movs r0, #42
; THUMB-ENABLE-NEXT:    bx lr
; THUMB-ENABLE-NEXT:  LBB8_2: @ %if.abort
; THUMB-ENABLE-NEXT:    push {r4, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #4
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    mov.w r0, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    bl _abort
;
; THUMB-DISABLE-LABEL: noreturn:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #4
; THUMB-DISABLE-NEXT:    cbnz r0, LBB8_2
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %if.end
; THUMB-DISABLE-NEXT:    movs r0, #42
; THUMB-DISABLE-NEXT:    pop {r4, r7, pc}
; THUMB-DISABLE-NEXT:  LBB8_2: @ %if.abort
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    mov.w r0, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    bl _abort
entry:
  %tobool = icmp eq i8 %bad_thing, 0
  br i1 %tobool, label %if.end, label %if.abort

if.abort:
  %call = tail call i32 asm sideeffect "mov $0, #1", "=r,~{r4}"()
  tail call void @abort() #0
  unreachable

if.end:
  ret i32 42
}

declare void @abort() #0

attributes #0 = { noreturn nounwind }

; Make sure that we handle infinite loops properly When checking that the Save
; and Restore blocks are control flow equivalent, the loop searches for the
; immediate (post) dominator for the (restore) save blocks. When either the Save
; or Restore block is located in an infinite loop the only immediate (post)
; dominator is itself. In this case, we cannot perform shrink wrapping, but we
; should return gracefully and continue compilation.
; The only condition for this test is the compilation finishes correctly.
; infiniteloop
; pop
define void @infiniteloop() "frame-pointer"="all" {
; ARM-LABEL: infiniteloop:
; ARM:       @ %bb.0: @ %entry
; ARM-NEXT:    push {r4, r5, r7, lr}
; ARM-NEXT:    add r7, sp, #8
; ARM-NEXT:    mov r0, #0
; ARM-NEXT:    cmp r0, #0
; ARM-NEXT:    bne LBB9_3
; ARM-NEXT:  @ %bb.1: @ %if.then
; ARM-NEXT:    sub r1, sp, #16
; ARM-NEXT:    mov sp, r1
; ARM-NEXT:  LBB9_2: @ %for.body
; ARM-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-NEXT:    @ InlineAsm Start
; ARM-NEXT:    mov r2, #1
; ARM-NEXT:    @ InlineAsm End
; ARM-NEXT:    add r0, r2, r0
; ARM-NEXT:    str r0, [r1]
; ARM-NEXT:    b LBB9_2
; ARM-NEXT:  LBB9_3: @ %if.end
; ARM-NEXT:    sub sp, r7, #8
; ARM-NEXT:    pop {r4, r5, r7, pc}
;
; THUMB-LABEL: infiniteloop:
; THUMB:       @ %bb.0: @ %entry
; THUMB-NEXT:    push {r4, r5, r7, lr}
; THUMB-NEXT:    add r7, sp, #8
; THUMB-NEXT:    movs r0, #0
; THUMB-NEXT:    cbnz r0, LBB9_3
; THUMB-NEXT:  @ %bb.1: @ %if.then
; THUMB-NEXT:    sub.w r0, sp, #16
; THUMB-NEXT:    mov sp, r0
; THUMB-NEXT:    movs r1, #0
; THUMB-NEXT:  LBB9_2: @ %for.body
; THUMB-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-NEXT:    @ InlineAsm Start
; THUMB-NEXT:    mov.w r2, #1
; THUMB-NEXT:    @ InlineAsm End
; THUMB-NEXT:    add r1, r2
; THUMB-NEXT:    str r1, [r0]
; THUMB-NEXT:    b LBB9_2
; THUMB-NEXT:  LBB9_3: @ %if.end
; THUMB-NEXT:    sub.w r4, r7, #8
; THUMB-NEXT:    mov sp, r4
; THUMB-NEXT:    pop {r4, r5, r7, pc}
; ARM-ENABLE-LABEL: infiniteloop:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    push {r4, r5, r7, lr}
; ARM-ENABLE-NEXT:    add r7, sp, #8
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    bne LBB9_3
; ARM-ENABLE-NEXT:  @ %bb.1: @ %if.then
; ARM-ENABLE-NEXT:    sub r1, sp, #16
; ARM-ENABLE-NEXT:    mov sp, r1
; ARM-ENABLE-NEXT:  LBB9_2: @ %for.body
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    @ InlineAsm Start
; ARM-ENABLE-NEXT:    mov r2, #1
; ARM-ENABLE-NEXT:    @ InlineAsm End
; ARM-ENABLE-NEXT:    add r0, r2, r0
; ARM-ENABLE-NEXT:    str r0, [r1]
; ARM-ENABLE-NEXT:    b LBB9_2
; ARM-ENABLE-NEXT:  LBB9_3: @ %if.end
; ARM-ENABLE-NEXT:    sub sp, r7, #8
; ARM-ENABLE-NEXT:    pop {r4, r5, r7, pc}
;
; ARM-DISABLE-LABEL: infiniteloop:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    push {r4, r5, r7, lr}
; ARM-DISABLE-NEXT:    add r7, sp, #8
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    bne LBB9_3
; ARM-DISABLE-NEXT:  @ %bb.1: @ %if.then
; ARM-DISABLE-NEXT:    sub r1, sp, #16
; ARM-DISABLE-NEXT:    mov sp, r1
; ARM-DISABLE-NEXT:  LBB9_2: @ %for.body
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    @ InlineAsm Start
; ARM-DISABLE-NEXT:    mov r2, #1
; ARM-DISABLE-NEXT:    @ InlineAsm End
; ARM-DISABLE-NEXT:    add r0, r2, r0
; ARM-DISABLE-NEXT:    str r0, [r1]
; ARM-DISABLE-NEXT:    b LBB9_2
; ARM-DISABLE-NEXT:  LBB9_3: @ %if.end
; ARM-DISABLE-NEXT:    sub sp, r7, #8
; ARM-DISABLE-NEXT:    pop {r4, r5, r7, pc}
;
; THUMB-ENABLE-LABEL: infiniteloop:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    push {r4, r5, r7, lr}
; THUMB-ENABLE-NEXT:    add r7, sp, #8
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    cbnz r0, LBB9_3
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %if.then
; THUMB-ENABLE-NEXT:    sub.w r0, sp, #16
; THUMB-ENABLE-NEXT:    mov sp, r0
; THUMB-ENABLE-NEXT:    movs r1, #0
; THUMB-ENABLE-NEXT:  LBB9_2: @ %for.body
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    @ InlineAsm Start
; THUMB-ENABLE-NEXT:    mov.w r2, #1
; THUMB-ENABLE-NEXT:    @ InlineAsm End
; THUMB-ENABLE-NEXT:    add r1, r2
; THUMB-ENABLE-NEXT:    str r1, [r0]
; THUMB-ENABLE-NEXT:    b LBB9_2
; THUMB-ENABLE-NEXT:  LBB9_3: @ %if.end
; THUMB-ENABLE-NEXT:    sub.w r4, r7, #8
; THUMB-ENABLE-NEXT:    mov sp, r4
; THUMB-ENABLE-NEXT:    pop {r4, r5, r7, pc}
;
; THUMB-DISABLE-LABEL: infiniteloop:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    push {r4, r5, r7, lr}
; THUMB-DISABLE-NEXT:    add r7, sp, #8
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    cbnz r0, LBB9_3
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %if.then
; THUMB-DISABLE-NEXT:    sub.w r0, sp, #16
; THUMB-DISABLE-NEXT:    mov sp, r0
; THUMB-DISABLE-NEXT:    movs r1, #0
; THUMB-DISABLE-NEXT:  LBB9_2: @ %for.body
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    @ InlineAsm Start
; THUMB-DISABLE-NEXT:    mov.w r2, #1
; THUMB-DISABLE-NEXT:    @ InlineAsm End
; THUMB-DISABLE-NEXT:    add r1, r2
; THUMB-DISABLE-NEXT:    str r1, [r0]
; THUMB-DISABLE-NEXT:    b LBB9_2
; THUMB-DISABLE-NEXT:  LBB9_3: @ %if.end
; THUMB-DISABLE-NEXT:    sub.w r4, r7, #8
; THUMB-DISABLE-NEXT:    mov sp, r4
; THUMB-DISABLE-NEXT:    pop {r4, r5, r7, pc}
entry:
  br i1 undef, label %if.then, label %if.end

if.then:
  %ptr = alloca i32, i32 4
  br label %for.body

for.body:                                         ; preds = %for.body, %entry
  %sum.03 = phi i32 [ 0, %if.then ], [ %add, %for.body ]
  %call = tail call i32 asm sideeffect "mov $0, #1", "=r,~{r4}"()
  %add = add nsw i32 %call, %sum.03
  store i32 %add, i32* %ptr
  br label %for.body

if.end:
  ret void
}

; Another infinite loop test this time with a body bigger than just one block.
; infiniteloop2
; pop
define void @infiniteloop2() "frame-pointer"="all" {
entry:
  br i1 undef, label %if.then, label %if.end

if.then:
  %ptr = alloca i32, i32 4
  br label %for.body

for.body:                                         ; preds = %for.body, %entry
  %sum.03 = phi i32 [ 0, %if.then ], [ %add, %body1 ], [ 1, %body2]
  %call = tail call i32 asm "mov $0, #0", "=r,~{r4}"()
  %add = add nsw i32 %call, %sum.03
  store i32 %add, i32* %ptr
  br i1 undef, label %body1, label %body2

body1:
  tail call void asm sideeffect "nop", "~{r4}"()
  br label %for.body

body2:
  tail call void asm sideeffect "nop", "~{r4}"()
  br label %for.body

if.end:
  ret void
}

; Another infinite loop test this time with two nested infinite loop.
; infiniteloop3
; bx lr
define void @infiniteloop3() "frame-pointer"="all" {
; ARM-LABEL: infiniteloop3:
; ARM:       @ %bb.0: @ %entry
; ARM-NEXT:    mov r0, #0
; ARM-NEXT:    cmp r0, #0
; ARM-NEXT:    bne LBB11_5
; ARM-NEXT:  @ %bb.1: @ %loop2a.preheader
; ARM-NEXT:    mov r1, #0
; ARM-NEXT:    mov r2, r0
; ARM-NEXT:    b LBB11_3
; ARM-NEXT:  LBB11_2: @ %loop2b
; ARM-NEXT:    @ in Loop: Header=BB11_3 Depth=1
; ARM-NEXT:    str r1, [r2]
; ARM-NEXT:    mov r2, r1
; ARM-NEXT:    mov r1, r3
; ARM-NEXT:  LBB11_3: @ %loop1
; ARM-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-NEXT:    ldr r3, [r0]
; ARM-NEXT:    cmp r0, #0
; ARM-NEXT:    bne LBB11_2
; ARM-NEXT:  @ %bb.4: @ in Loop: Header=BB11_3 Depth=1
; ARM-NEXT:    mov r0, r1
; ARM-NEXT:    mov r1, r3
; ARM-NEXT:    mov r2, r0
; ARM-NEXT:    b LBB11_3
; ARM-NEXT:  LBB11_5: @ %end
; ARM-NEXT:    bx lr
;
; THUMB-LABEL: infiniteloop3:
; THUMB:       @ %bb.0: @ %entry
; THUMB-NEXT:    movs r0, #0
; THUMB-NEXT:    cbnz r0, LBB11_5
; THUMB-NEXT:  @ %bb.1: @ %loop2a.preheader
; THUMB-NEXT:    movs r0, #0
; THUMB-NEXT:    movs r1, #0
; THUMB-NEXT:    mov r2, r0
; THUMB-NEXT:    b LBB11_3
; THUMB-NEXT:  LBB11_2: @ %loop2b
; THUMB-NEXT:    @ in Loop: Header=BB11_3 Depth=1
; THUMB-NEXT:    str r1, [r2]
; THUMB-NEXT:    mov r2, r1
; THUMB-NEXT:    mov r1, r3
; THUMB-NEXT:  LBB11_3: @ %loop1
; THUMB-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-NEXT:    ldr r3, [r0]
; THUMB-NEXT:    cmp r0, #0
; THUMB-NEXT:    bne LBB11_2
; THUMB-NEXT:  @ %bb.4: @ in Loop: Header=BB11_3 Depth=1
; THUMB-NEXT:    mov r0, r1
; THUMB-NEXT:    mov r1, r3
; THUMB-NEXT:    mov r2, r0
; THUMB-NEXT:    b LBB11_3
; THUMB-NEXT:  LBB11_5: @ %end
; THUMB-NEXT:    bx lr
; ARM-ENABLE-LABEL: infiniteloop3:
; ARM-ENABLE:       @ %bb.0: @ %entry
; ARM-ENABLE-NEXT:    mov r0, #0
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    bne LBB11_5
; ARM-ENABLE-NEXT:  @ %bb.1: @ %loop2a.preheader
; ARM-ENABLE-NEXT:    mov r1, #0
; ARM-ENABLE-NEXT:    mov r2, r0
; ARM-ENABLE-NEXT:    b LBB11_3
; ARM-ENABLE-NEXT:  LBB11_2: @ %loop2b
; ARM-ENABLE-NEXT:    @ in Loop: Header=BB11_3 Depth=1
; ARM-ENABLE-NEXT:    str r1, [r2]
; ARM-ENABLE-NEXT:    mov r2, r1
; ARM-ENABLE-NEXT:    mov r1, r3
; ARM-ENABLE-NEXT:  LBB11_3: @ %loop1
; ARM-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-ENABLE-NEXT:    ldr r3, [r0]
; ARM-ENABLE-NEXT:    cmp r0, #0
; ARM-ENABLE-NEXT:    bne LBB11_2
; ARM-ENABLE-NEXT:  @ %bb.4: @ in Loop: Header=BB11_3 Depth=1
; ARM-ENABLE-NEXT:    mov r0, r1
; ARM-ENABLE-NEXT:    mov r1, r3
; ARM-ENABLE-NEXT:    mov r2, r0
; ARM-ENABLE-NEXT:    b LBB11_3
; ARM-ENABLE-NEXT:  LBB11_5: @ %end
; ARM-ENABLE-NEXT:    bx lr
;
; ARM-DISABLE-LABEL: infiniteloop3:
; ARM-DISABLE:       @ %bb.0: @ %entry
; ARM-DISABLE-NEXT:    mov r0, #0
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    bne LBB11_5
; ARM-DISABLE-NEXT:  @ %bb.1: @ %loop2a.preheader
; ARM-DISABLE-NEXT:    mov r1, #0
; ARM-DISABLE-NEXT:    mov r2, r0
; ARM-DISABLE-NEXT:    b LBB11_3
; ARM-DISABLE-NEXT:  LBB11_2: @ %loop2b
; ARM-DISABLE-NEXT:    @ in Loop: Header=BB11_3 Depth=1
; ARM-DISABLE-NEXT:    str r1, [r2]
; ARM-DISABLE-NEXT:    mov r2, r1
; ARM-DISABLE-NEXT:    mov r1, r3
; ARM-DISABLE-NEXT:  LBB11_3: @ %loop1
; ARM-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; ARM-DISABLE-NEXT:    ldr r3, [r0]
; ARM-DISABLE-NEXT:    cmp r0, #0
; ARM-DISABLE-NEXT:    bne LBB11_2
; ARM-DISABLE-NEXT:  @ %bb.4: @ in Loop: Header=BB11_3 Depth=1
; ARM-DISABLE-NEXT:    mov r0, r1
; ARM-DISABLE-NEXT:    mov r1, r3
; ARM-DISABLE-NEXT:    mov r2, r0
; ARM-DISABLE-NEXT:    b LBB11_3
; ARM-DISABLE-NEXT:  LBB11_5: @ %end
; ARM-DISABLE-NEXT:    bx lr
;
; THUMB-ENABLE-LABEL: infiniteloop3:
; THUMB-ENABLE:       @ %bb.0: @ %entry
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    cbnz r0, LBB11_5
; THUMB-ENABLE-NEXT:  @ %bb.1: @ %loop2a.preheader
; THUMB-ENABLE-NEXT:    movs r0, #0
; THUMB-ENABLE-NEXT:    movs r1, #0
; THUMB-ENABLE-NEXT:    mov r2, r0
; THUMB-ENABLE-NEXT:    b LBB11_3
; THUMB-ENABLE-NEXT:  LBB11_2: @ %loop2b
; THUMB-ENABLE-NEXT:    @ in Loop: Header=BB11_3 Depth=1
; THUMB-ENABLE-NEXT:    str r1, [r2]
; THUMB-ENABLE-NEXT:    mov r2, r1
; THUMB-ENABLE-NEXT:    mov r1, r3
; THUMB-ENABLE-NEXT:  LBB11_3: @ %loop1
; THUMB-ENABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-ENABLE-NEXT:    ldr r3, [r0]
; THUMB-ENABLE-NEXT:    cmp r0, #0
; THUMB-ENABLE-NEXT:    bne LBB11_2
; THUMB-ENABLE-NEXT:  @ %bb.4: @ in Loop: Header=BB11_3 Depth=1
; THUMB-ENABLE-NEXT:    mov r0, r1
; THUMB-ENABLE-NEXT:    mov r1, r3
; THUMB-ENABLE-NEXT:    mov r2, r0
; THUMB-ENABLE-NEXT:    b LBB11_3
; THUMB-ENABLE-NEXT:  LBB11_5: @ %end
; THUMB-ENABLE-NEXT:    bx lr
;
; THUMB-DISABLE-LABEL: infiniteloop3:
; THUMB-DISABLE:       @ %bb.0: @ %entry
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    cbnz r0, LBB11_5
; THUMB-DISABLE-NEXT:  @ %bb.1: @ %loop2a.preheader
; THUMB-DISABLE-NEXT:    movs r0, #0
; THUMB-DISABLE-NEXT:    movs r1, #0
; THUMB-DISABLE-NEXT:    mov r2, r0
; THUMB-DISABLE-NEXT:    b LBB11_3
; THUMB-DISABLE-NEXT:  LBB11_2: @ %loop2b
; THUMB-DISABLE-NEXT:    @ in Loop: Header=BB11_3 Depth=1
; THUMB-DISABLE-NEXT:    str r1, [r2]
; THUMB-DISABLE-NEXT:    mov r2, r1
; THUMB-DISABLE-NEXT:    mov r1, r3
; THUMB-DISABLE-NEXT:  LBB11_3: @ %loop1
; THUMB-DISABLE-NEXT:    @ =>This Inner Loop Header: Depth=1
; THUMB-DISABLE-NEXT:    ldr r3, [r0]
; THUMB-DISABLE-NEXT:    cmp r0, #0
; THUMB-DISABLE-NEXT:    bne LBB11_2
; THUMB-DISABLE-NEXT:  @ %bb.4: @ in Loop: Header=BB11_3 Depth=1
; THUMB-DISABLE-NEXT:    mov r0, r1
; THUMB-DISABLE-NEXT:    mov r1, r3
; THUMB-DISABLE-NEXT:    mov r2, r0
; THUMB-DISABLE-NEXT:    b LBB11_3
; THUMB-DISABLE-NEXT:  LBB11_5: @ %end
; THUMB-DISABLE-NEXT:    bx lr
entry:
  br i1 undef, label %loop2a, label %body

body:                                             ; preds = %entry
  br i1 undef, label %loop2a, label %end

loop1:                                            ; preds = %loop2a, %loop2b
  %var.phi = phi i32* [ %next.phi, %loop2b ], [ %var, %loop2a ]
  %next.phi = phi i32* [ %next.load, %loop2b ], [ %next.var, %loop2a ]
  %0 = icmp eq i32* %var, null
  %next.load = load i32*, i32** undef
  br i1 %0, label %loop2a, label %loop2b

loop2a:                                           ; preds = %loop1, %body, %entry
  %var = phi i32* [ null, %body ], [ null, %entry ], [ %next.phi, %loop1 ]
  %next.var = phi i32* [ undef, %body ], [ null, %entry ], [ %next.load, %loop1 ]
  br label %loop1

loop2b:                                           ; preds = %loop1
  %gep1 = bitcast i32* %var.phi to i32*
  %next.ptr = bitcast i32* %gep1 to i32**
  store i32* %next.phi, i32** %next.ptr
  br label %loop1

end:
  ret void
}

; Function Attrs: nounwind readnone
declare double @llvm.pow.f64(double, double)

; This function needs to spill floating point registers to
; exercise the path where we were dereferencing the end iterator
; to access debug info location while inserting the spill code
; during PEI with shrink-wrapping enable.
; debug_info:
;
; {{tst  r2, #1|lsls r1, r2, #31}}
; beq      [[BB13:LBB[0-9_]+]]
;
; push
;
; {{tst  r2, #1|lsls r1, r2, #31}}
; beq      [[BB13:LBB[0-9_]+]]
;
; bl{{x?}} _pow
;
;
; pop
;
; [[BB13]]:
; vldr
;
; pop
;
; FIXME: This is flakey passing by finding 'bl' somewhere amongst the debug
; info (like labels named 'line_table) not because it's found a bl instruction.
;
; bl
define float @debug_info(float %gamma, float %slopeLimit, i1 %or.cond, double %tmp) "frame-pointer"="all" {
; ARM-LABEL: debug_info:
; ARM:       @ %bb.0: @ %bb
; ARM-NEXT:    push {r4, r7, lr}
; ARM-NEXT:    add r7, sp, #4
; ARM-NEXT:    sub r4, sp, #16
; ARM-NEXT:    bfc r4, #0, #4
; ARM-NEXT:    mov sp, r4
; ARM-NEXT:    tst r2, #1
; ARM-NEXT:    vst1.64 {d8, d9}, [r4:128]
; ARM-NEXT:    beq LBB12_2
; ARM-NEXT:  @ %bb.1: @ %bb3
; ARM-NEXT:    ldr r1, [r7, #8]
; ARM-NEXT:    vmov s16, r0
; ARM-NEXT:    mov r0, r3
; ARM-NEXT:    mov r2, r3
; ARM-NEXT:    vmov d9, r3, r1
; ARM-NEXT:    mov r3, r1
; ARM-NEXT:    bl _pow
; ARM-NEXT:    vmov.f32 s0, #1.000000e+00
; ARM-NEXT:    vmov.f64 d16, #1.000000e+00
; ARM-NEXT:    vadd.f64 d16, d9, d16
; ARM-NEXT:    vcmp.f32 s16, s0
; ARM-NEXT:    vmrs APSR_nzcv, fpscr
; ARM-NEXT:    vmov d17, r0, r1
; ARM-NEXT:    vmov.f64 d18, d9
; ARM-NEXT:    vadd.f64 d17, d17, d17
; ARM-NEXT:    vmovgt.f64 d18, d16
; ARM-NEXT:    vcmp.f64 d18, d9
; ARM-NEXT:    vmrs APSR_nzcv, fpscr
; ARM-NEXT:    vmovne.f64 d9, d17
; ARM-NEXT:    vcvt.f32.f64 s0, d9
; ARM-NEXT:    b LBB12_3
; ARM-NEXT:  LBB12_2:
; ARM-NEXT:    vldr s0, LCPI12_0
; ARM-NEXT:  LBB12_3: @ %bb13
; ARM-NEXT:    mov r4, sp
; ARM-NEXT:    vld1.64 {d8, d9}, [r4:128]
; ARM-NEXT:    vmov r0, s0
; ARM-NEXT:    sub sp, r7, #4
; ARM-NEXT:    pop {r4, r7, pc}
; ARM-NEXT:    .p2align 2
; ARM-NEXT:  @ %bb.4:
; ARM-NEXT:    .data_region
; ARM-NEXT:  LCPI12_0:
; ARM-NEXT:    .long 0 @ float 0
; ARM-NEXT:    .end_data_region
;
; THUMB-LABEL: debug_info:
; THUMB:       @ %bb.0: @ %bb
; THUMB-NEXT:    push {r4, r7, lr}
; THUMB-NEXT:    add r7, sp, #4
; THUMB-NEXT:    sub.w r4, sp, #16
; THUMB-NEXT:    bfc r4, #0, #4
; THUMB-NEXT:    mov sp, r4
; THUMB-NEXT:    lsls r1, r2, #31
; THUMB-NEXT:    vst1.64 {d8, d9}, [r4:128]
; THUMB-NEXT:    beq LBB12_2
; THUMB-NEXT:  @ %bb.1: @ %bb3
; THUMB-NEXT:    ldr r1, [r7, #8]
; THUMB-NEXT:    vmov s16, r0
; THUMB-NEXT:    mov r0, r3
; THUMB-NEXT:    mov r2, r3
; THUMB-NEXT:    vmov d9, r3, r1
; THUMB-NEXT:    mov r3, r1
; THUMB-NEXT:    bl _pow
; THUMB-NEXT:    vmov.f32 s0, #1.000000e+00
; THUMB-NEXT:    vmov.f64 d16, #1.000000e+00
; THUMB-NEXT:    vmov.f64 d18, d9
; THUMB-NEXT:    vcmp.f32 s16, s0
; THUMB-NEXT:    vadd.f64 d16, d9, d16
; THUMB-NEXT:    vmrs APSR_nzcv, fpscr
; THUMB-NEXT:    it gt
; THUMB-NEXT:    vmovgt.f64 d18, d16
; THUMB-NEXT:    vcmp.f64 d18, d9
; THUMB-NEXT:    vmov d17, r0, r1
; THUMB-NEXT:    vmrs APSR_nzcv, fpscr
; THUMB-NEXT:    vadd.f64 d17, d17, d17
; THUMB-NEXT:    it ne
; THUMB-NEXT:    vmovne.f64 d9, d17
; THUMB-NEXT:    vcvt.f32.f64 s0, d9
; THUMB-NEXT:    b LBB12_3
; THUMB-NEXT:  LBB12_2:
; THUMB-NEXT:    vldr s0, LCPI12_0
; THUMB-NEXT:  LBB12_3: @ %bb13
; THUMB-NEXT:    mov r4, sp
; THUMB-NEXT:    vld1.64 {d8, d9}, [r4:128]
; THUMB-NEXT:    subs r4, r7, #4
; THUMB-NEXT:    vmov r0, s0
; THUMB-NEXT:    mov sp, r4
; THUMB-NEXT:    pop {r4, r7, pc}
; THUMB-NEXT:    .p2align 2
; THUMB-NEXT:  @ %bb.4:
; THUMB-NEXT:    .data_region
; THUMB-NEXT:  LCPI12_0:
; THUMB-NEXT:    .long 0 @ float 0
; THUMB-NEXT:    .end_data_region
bb:
  br i1 %or.cond, label %bb3, label %bb13

bb3:                                              ; preds = %bb
  %tmp4 = fcmp ogt float %gamma, 1.000000e+00
  %tmp5 = fadd double 1.000000e+00, %tmp
  %tmp6 = select i1 %tmp4, double %tmp5, double %tmp
  %tmp10 = tail call double @llvm.pow.f64(double %tmp, double %tmp)
  %tmp11 = fcmp une double %tmp6, %tmp
  %tmp12 = fadd double %tmp10, %tmp10
  %cutoff.0 = select i1 %tmp11, double %tmp12, double %tmp
  %phitmp = fptrunc double %cutoff.0 to float
  br label %bb13

bb13:                                             ; preds = %bb3, %bb
  %cutoff.1 = phi float [ 0.000000e+00, %bb ], [ %phitmp, %bb3 ]
  ret float %cutoff.1
}


!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "LLVM", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !4, globals: !2, imports: !2)
!1 = !DIFile(filename: "a.cpp", directory: "b")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{!5}
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)