Commit 107601e
authored
[InstCombine] Allow min/max in constant BOp min/max folding (#142878)
Extend folding for `X Pred C2 ? X BOp C1 : C2 BOp C1` to `min/max(X, C2)
BOp C1` to allow min and max as `BOp`. This ensures a constant clamping
pattern is folded into a pair of min/max instructions. Here is a
simplified example of a case where this folding is not occurring
currently.
int clampToU8(int v) {
if (v < 0) return 0;
if (v > 255) return 255;
return v;
}
https://godbolt.org/z/78jhKPWbv
Generic proof: https://alive2.llvm.org/ce/z/cdpLYy1 parent bc7f1ea commit 107601e
File tree
2 files changed
+84
-14
lines changed- llvm
- lib/Transforms/InstCombine
- test/Transforms/InstCombine
2 files changed
+84
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1826 | 1826 | | |
1827 | 1827 | | |
1828 | 1828 | | |
1829 | | - | |
1830 | 1829 | | |
1831 | 1830 | | |
1832 | 1831 | | |
| |||
1842 | 1841 | | |
1843 | 1842 | | |
1844 | 1843 | | |
1845 | | - | |
| 1844 | + | |
1846 | 1845 | | |
1847 | 1846 | | |
1848 | | - | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
1849 | 1852 | | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
1854 | | - | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
1855 | 1858 | | |
1856 | | - | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
1857 | 1868 | | |
| 1869 | + | |
1858 | 1870 | | |
1859 | 1871 | | |
1860 | 1872 | | |
1861 | | - | |
| 1873 | + | |
1862 | 1874 | | |
1863 | 1875 | | |
1864 | | - | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
1865 | 1883 | | |
1866 | 1884 | | |
1867 | | - | |
1868 | | - | |
| 1885 | + | |
1869 | 1886 | | |
1870 | 1887 | | |
1871 | 1888 | | |
| |||
1874 | 1891 | | |
1875 | 1892 | | |
1876 | 1893 | | |
1877 | | - | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
1878 | 1897 | | |
1879 | 1898 | | |
1880 | 1899 | | |
| |||
Lines changed: 51 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 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 | + | |
0 commit comments