Commit cdfaef9
committed
[InstCombine] When canoncicalizing clamp like, also consider certain sgt/slt cases
In particular, when %target_low=0 and %target_high=-1 and C1=0
```
%old_cmp1 = icmp slt %x, C2
%old_replacement = select %old_cmp1, %target_low, %target_high
```
might have aleady been combined into
```
%old_cmp1 = icmp sgt %x, C2
%old_replacement = sext %old_cmp1
```
For this particular case, the canonacalization allows for a more optimized sequence
utilizing `max` to be created.
```
%old_cmp1 = icmp sgt %x, C2
%old_replacement = sext %old_cmp1
%old_cmp0 = icmp ult i32 %x, C0
%r = select i1 %old_cmp0, i32 %x, i32 %old_replacement
```
If 0 s<= C2 s<= C0, can be re-written as:
```
%new_cmp1 = icmp slt i32 %x, 0
%new_cmp2 = icmp sge i32 %x, C0
%new_clamped_low = select i1 %new_cmp1, i32 0, i32 %x
%r = select i1 %new_cmp2, i32 -1, i32 %new_clamped_low
```
Can be re-written as (already occurs from the canonicalized version):
```
%clamped_low = max i32 %x, 0
%new_cmp2 = icmp sge i32 %x, C0
%sext = sext i1 %new_cmp2
%r = or i32 %sext, %new_cmp2
```1 parent 46767d0 commit cdfaef9
File tree
2 files changed
+52
-23
lines changed- llvm
- lib/Transforms/InstCombine
- test/Transforms/InstCombine
2 files changed
+52
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1521 | 1521 | | |
1522 | 1522 | | |
1523 | 1523 | | |
1524 | | - | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
1528 | 1535 | | |
1529 | 1536 | | |
1530 | 1537 | | |
| |||
1575 | 1582 | | |
1576 | 1583 | | |
1577 | 1584 | | |
| 1585 | + | |
1578 | 1586 | | |
1579 | 1587 | | |
1580 | 1588 | | |
1581 | 1589 | | |
1582 | | - | |
1583 | | - | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
1584 | 1599 | | |
1585 | 1600 | | |
1586 | 1601 | | |
1587 | 1602 | | |
1588 | 1603 | | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
1589 | 1609 | | |
1590 | 1610 | | |
1591 | 1611 | | |
1592 | 1612 | | |
1593 | 1613 | | |
1594 | 1614 | | |
1595 | 1615 | | |
| 1616 | + | |
1596 | 1617 | | |
1597 | 1618 | | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
1598 | 1623 | | |
1599 | 1624 | | |
1600 | 1625 | | |
| |||
1615 | 1640 | | |
1616 | 1641 | | |
1617 | 1642 | | |
1618 | | - | |
| 1643 | + | |
1619 | 1644 | | |
1620 | 1645 | | |
1621 | 1646 | | |
| |||
1644 | 1669 | | |
1645 | 1670 | | |
1646 | 1671 | | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
1647 | 1680 | | |
1648 | 1681 | | |
1649 | 1682 | | |
| |||
Lines changed: 12 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
67 | 65 | | |
68 | 66 | | |
69 | 67 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
74 | 71 | | |
75 | 72 | | |
76 | 73 | | |
| |||
83 | 80 | | |
84 | 81 | | |
85 | 82 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
90 | 86 | | |
91 | 87 | | |
92 | 88 | | |
| |||
0 commit comments