Commit d4cc755
Automerge: [AArch64] Reorder Comparison Trees to Facilitate CSE (#168064)
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.File tree
2 files changed
+170
-10
lines changed- llvm
- lib/Target/AArch64
- test/CodeGen/AArch64
2 files changed
+170
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3886 | 3886 | | |
3887 | 3887 | | |
3888 | 3888 | | |
| 3889 | + | |
| 3890 | + | |
3889 | 3891 | | |
3890 | 3892 | | |
3891 | 3893 | | |
3892 | 3894 | | |
3893 | 3895 | | |
3894 | | - | |
3895 | | - | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
3896 | 3899 | | |
3897 | 3900 | | |
3898 | 3901 | | |
3899 | 3902 | | |
3900 | 3903 | | |
3901 | | - | |
| 3904 | + | |
| 3905 | + | |
3902 | 3906 | | |
3903 | 3907 | | |
3904 | 3908 | | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
3905 | 3913 | | |
3906 | 3914 | | |
3907 | 3915 | | |
| |||
3913 | 3921 | | |
3914 | 3922 | | |
3915 | 3923 | | |
3916 | | - | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
3917 | 3927 | | |
3918 | 3928 | | |
3919 | 3929 | | |
3920 | | - | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
3921 | 3933 | | |
3922 | 3934 | | |
3923 | 3935 | | |
| |||
3940 | 3952 | | |
3941 | 3953 | | |
3942 | 3954 | | |
| 3955 | + | |
3943 | 3956 | | |
3944 | 3957 | | |
3945 | 3958 | | |
| |||
4001 | 4014 | | |
4002 | 4015 | | |
4003 | 4016 | | |
4004 | | - | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
4005 | 4020 | | |
4006 | 4021 | | |
4007 | 4022 | | |
4008 | 4023 | | |
4009 | 4024 | | |
4010 | 4025 | | |
4011 | | - | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
4012 | 4029 | | |
4013 | 4030 | | |
4014 | 4031 | | |
4015 | | - | |
4016 | | - | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
4017 | 4036 | | |
4018 | 4037 | | |
4019 | 4038 | | |
| |||
4069 | 4088 | | |
4070 | 4089 | | |
4071 | 4090 | | |
4072 | | - | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
4073 | 4094 | | |
4074 | 4095 | | |
4075 | 4096 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
0 commit comments