Commit 03118af
committed
[AArch64] Reorder Comparison Trees to Facilitate CSE
The AArch64 backend converts trees formed by conjunctions/disjunctions
of comparisons into sequences of `CCMP` instructions. The implementation
before this change checks whether a sub-tree must be processed first. If
not, it processes the operations in the order they occur in the DAG.
This may not be optimal if there is a corresponding `SUB` node for one
of the comparisons. In this case, we should process this comparison
first because we can then use the same instruction for the `SUB` node
and the comparison.
To achieve this, this commit comprises the following changes:
- Extend `canEmitConjunction` with a new output parameter `PreferFirst`,
which reports to the caller whether the sub-tree should preferably be
processed first.
- Set `PreferFirst` to `true` if we can find a corresponding `SUB` node
in the DAG.
- If we can process a sub-tree with `PreferFirst = true` first (i.e., we
do not violate any `MustBeFirst` constraint by doing so), we swap the
sub-trees.
- The already existing code for performing the common subexpression
elimination takes care to use only a single instruction for the
comparison and the `SUB` node if possible.
Closes #149685.1 parent 39b54ba commit 03118af
File tree
2 files changed
+44
-29
lines changed- llvm
- lib/Target/AArch64
- test/CodeGen/AArch64
2 files changed
+44
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3874 | 3874 | | |
3875 | 3875 | | |
3876 | 3876 | | |
| 3877 | + | |
| 3878 | + | |
3877 | 3879 | | |
3878 | 3880 | | |
3879 | 3881 | | |
3880 | 3882 | | |
3881 | 3883 | | |
3882 | | - | |
3883 | | - | |
| 3884 | + | |
| 3885 | + | |
3884 | 3886 | | |
3885 | 3887 | | |
3886 | 3888 | | |
3887 | 3889 | | |
3888 | 3890 | | |
3889 | | - | |
| 3891 | + | |
| 3892 | + | |
3890 | 3893 | | |
3891 | 3894 | | |
3892 | 3895 | | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
3893 | 3900 | | |
3894 | 3901 | | |
3895 | 3902 | | |
| |||
3901 | 3908 | | |
3902 | 3909 | | |
3903 | 3910 | | |
3904 | | - | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
3905 | 3914 | | |
3906 | 3915 | | |
3907 | 3916 | | |
3908 | | - | |
| 3917 | + | |
| 3918 | + | |
| 3919 | + | |
3909 | 3920 | | |
3910 | 3921 | | |
3911 | 3922 | | |
| |||
3928 | 3939 | | |
3929 | 3940 | | |
3930 | 3941 | | |
| 3942 | + | |
3931 | 3943 | | |
3932 | 3944 | | |
3933 | 3945 | | |
| |||
3989 | 4001 | | |
3990 | 4002 | | |
3991 | 4003 | | |
3992 | | - | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
3993 | 4007 | | |
3994 | 4008 | | |
3995 | 4009 | | |
3996 | 4010 | | |
3997 | 4011 | | |
3998 | 4012 | | |
3999 | | - | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
4000 | 4016 | | |
4001 | 4017 | | |
4002 | 4018 | | |
4003 | | - | |
4004 | | - | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
4005 | 4023 | | |
4006 | 4024 | | |
4007 | 4025 | | |
| |||
4057 | 4075 | | |
4058 | 4076 | | |
4059 | 4077 | | |
4060 | | - | |
| 4078 | + | |
| 4079 | + | |
| 4080 | + | |
4061 | 4081 | | |
4062 | 4082 | | |
4063 | 4083 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 22 | + | |
26 | 23 | | |
27 | | - | |
| 24 | + | |
| 25 | + | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
| |||
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 40 | + | |
45 | 41 | | |
46 | | - | |
| 42 | + | |
| 43 | + | |
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
| |||
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
65 | 61 | | |
66 | 62 | | |
67 | 63 | | |
| |||
74 | 70 | | |
75 | 71 | | |
76 | 72 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 73 | + | |
| 74 | + | |
80 | 75 | | |
81 | 76 | | |
82 | 77 | | |
| |||
0 commit comments