Commit 89d86b6
authored
SimplifyCFG: Enable switch replacements in more cases (#156477)
In some cases, we can replace a switch with simpler instructions or a
lookup table.
For instance, if every case results in the same value, we can simply
replace the switch
with that single value.
However, lookup tables are not always supported.
Targets, function attributes and compiler options can deactivate lookup
table creation.
Currently, even simpler switch replacements like the single value
optimization do not
get applied, because we only enable these transformations if lookup
tables are enabled.
This PR enables the other kinds of replacements, even if lookup tables
are not supported.
First, it checks if the potential replacements are lookup tables.
If they are, then check if lookup tables are supported and whether to
continue.
If they are not, then we can apply the other transformations.
Originally, lookup table creation was delayed until late stages of the
compilation pipeline, because
it can result in difficult-to-analyze code and prevent other
optimizations.
As a side effect of this change, we can also enable the simpler
optimizations much earlier in the
compilation process.1 parent 4aa59f5 commit 89d86b6
File tree
2 files changed
+537
-8
lines changed- llvm
- lib/Transforms/Utils
- test/Transforms/SimplifyCFG
2 files changed
+537
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6458 | 6458 | | |
6459 | 6459 | | |
6460 | 6460 | | |
| 6461 | + | |
| 6462 | + | |
| 6463 | + | |
6461 | 6464 | | |
6462 | 6465 | | |
6463 | 6466 | | |
| |||
6605 | 6608 | | |
6606 | 6609 | | |
6607 | 6610 | | |
6608 | | - | |
6609 | 6611 | | |
6610 | 6612 | | |
6611 | 6613 | | |
| |||
6625 | 6627 | | |
6626 | 6628 | | |
6627 | 6629 | | |
6628 | | - | |
6629 | 6630 | | |
6630 | 6631 | | |
6631 | 6632 | | |
| |||
6642 | 6643 | | |
6643 | 6644 | | |
6644 | 6645 | | |
| 6646 | + | |
6645 | 6647 | | |
6646 | 6648 | | |
6647 | 6649 | | |
| |||
6657 | 6659 | | |
6658 | 6660 | | |
6659 | 6661 | | |
| 6662 | + | |
6660 | 6663 | | |
6661 | 6664 | | |
6662 | 6665 | | |
| |||
6679 | 6682 | | |
6680 | 6683 | | |
6681 | 6684 | | |
| 6685 | + | |
6682 | 6686 | | |
6683 | 6687 | | |
6684 | 6688 | | |
| |||
6745 | 6749 | | |
6746 | 6750 | | |
6747 | 6751 | | |
| 6752 | + | |
| 6753 | + | |
6748 | 6754 | | |
6749 | 6755 | | |
6750 | 6756 | | |
| |||
6915 | 6921 | | |
6916 | 6922 | | |
6917 | 6923 | | |
6918 | | - | |
6919 | | - | |
6920 | | - | |
6921 | | - | |
6922 | | - | |
6923 | 6924 | | |
6924 | 6925 | | |
6925 | 6926 | | |
| |||
7078 | 7079 | | |
7079 | 7080 | | |
7080 | 7081 | | |
| 7082 | + | |
| 7083 | + | |
| 7084 | + | |
| 7085 | + | |
| 7086 | + | |
| 7087 | + | |
| 7088 | + | |
| 7089 | + | |
| 7090 | + | |
| 7091 | + | |
| 7092 | + | |
| 7093 | + | |
| 7094 | + | |
| 7095 | + | |
7081 | 7096 | | |
7082 | 7097 | | |
7083 | 7098 | | |
| |||
7219 | 7234 | | |
7220 | 7235 | | |
7221 | 7236 | | |
7222 | | - | |
7223 | 7237 | | |
7224 | 7238 | | |
7225 | 7239 | | |
| |||
0 commit comments