Commit f2a801b
committed
[InstCombine] Inverse is.fpclass mask operand, when profitable
The `@llvm.is.fpclass` intrinsic is matched and generated by the InstCombine
pass. When the number of set mask bits is greater than the number of the unset
bits, it's profitable to replace the `is.fpclass(x, mask)` intrinsic call with
a sequence of `!is.fpclass(x, ~mask)` operations.
The following IR snippets are semantically equivalent:
```LLVM
define i1 @src(float %src) {
; 639 == 0b1001111111
%class = call i1 @llvm.is.fpclass.f32(float %src, i32 639)
ret i1 %class
}
define i1 @tgt(float %src) {
; 384 == 0b0110000000 == ~0b1001111111 & 0x3ff == ~639 & 0x3ff
%class = call i1 @llvm.is.fpclass.f32(float %src, i32 384)
%not = xor i1 %class, true
ret i1 %not
}
```
However, the generated code is more efficient for the 2nd IR sequence,
at least on some targets.
References:
* https://alive2.llvm.org/ce/z/kkZhDt
* https://godbolt.org/z/5WE8Wb3vz1 parent f590963 commit f2a801b
File tree
7 files changed
+318
-118
lines changed- llvm
- lib/Transforms/InstCombine
- test/Transforms/InstCombine
7 files changed
+318
-118
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1522 | 1522 | | |
1523 | 1523 | | |
1524 | 1524 | | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
1528 | 1540 | | |
1529 | 1541 | | |
1530 | 1542 | | |
| |||
1610 | 1622 | | |
1611 | 1623 | | |
1612 | 1624 | | |
1613 | | - | |
1614 | | - | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
1615 | 1637 | | |
1616 | 1638 | | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
1617 | 1644 | | |
1618 | 1645 | | |
1619 | 1646 | | |
| |||
4651 | 4678 | | |
4652 | 4679 | | |
4653 | 4680 | | |
4654 | | - | |
4655 | | - | |
4656 | | - | |
4657 | | - | |
| 4681 | + | |
| 4682 | + | |
| 4683 | + | |
| 4684 | + | |
| 4685 | + | |
| 4686 | + | |
| 4687 | + | |
| 4688 | + | |
| 4689 | + | |
| 4690 | + | |
| 4691 | + | |
4658 | 4692 | | |
4659 | 4693 | | |
4660 | 4694 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1050 | 1050 | | |
1051 | 1051 | | |
1052 | 1052 | | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
1053 | 1067 | | |
1054 | 1068 | | |
1055 | 1069 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| |||
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
292 | | - | |
| 293 | + | |
| 294 | + | |
293 | 295 | | |
294 | 296 | | |
295 | 297 | | |
| |||
300 | 302 | | |
301 | 303 | | |
302 | 304 | | |
303 | | - | |
| 305 | + | |
| 306 | + | |
304 | 307 | | |
305 | 308 | | |
306 | 309 | | |
| |||
0 commit comments