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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
# RUN: llc -mtriple=aarch64-linux-gnu -run-pass machine-combiner -o - %s | FileCheck %s
# The test cases in this file check following transformation if the right form
# can reduce latency.
# A - (B + C) ==> (A - B) - C
---
# 32 bit.
# CHECK-LABEL: name: test1
# CHECK: [[TMP:%[0-9]+]]:gpr32common = SUBWrr killed %3, %4
# CHECK-NEXT: %7:gpr32 = SUBWrr killed [[TMP]], %5
name: test1
registers:
- { id: 0, class: gpr32common }
- { id: 1, class: gpr32 }
- { id: 2, class: gpr32 }
- { id: 3, class: gpr32common }
- { id: 4, class: gpr32common }
- { id: 5, class: gpr32 }
- { id: 6, class: gpr32 }
- { id: 7, class: gpr32 }
- { id: 8, class: gpr32 }
body: |
bb.0:
%2:gpr32 = COPY $w2
%1:gpr32 = COPY $w1
%0:gpr32common = COPY $w0
%3:gpr32common = ORRWri %2:gpr32, 1600
%4:gpr32common = ADDWri %0:gpr32common, 100, 0
%5:gpr32 = EORWrs %1:gpr32, %4:gpr32common, 8
%6:gpr32 = ADDWrr %5:gpr32, %4:gpr32common
%7:gpr32 = SUBWrr killed %3:gpr32common, killed %6:gpr32
%8:gpr32 = EORWrs killed %7:gpr32, %5:gpr32, 141
$w0 = COPY %8:gpr32
RET_ReallyLR implicit $w0
...
---
# 64 bit.
# CHECK-LABEL: name: test2
# CHECK: [[TMP:%[0-9]+]]:gpr64common = SUBXrr killed %3, %4
# CHECK-NEXT: %7:gpr64 = SUBXrr killed [[TMP]], %5
name: test2
registers:
- { id: 0, class: gpr64common }
- { id: 1, class: gpr64 }
- { id: 2, class: gpr64 }
- { id: 3, class: gpr64common }
- { id: 4, class: gpr64common }
- { id: 5, class: gpr64 }
- { id: 6, class: gpr64 }
- { id: 7, class: gpr64 }
- { id: 8, class: gpr64 }
body: |
bb.0:
%2:gpr64 = COPY $x2
%1:gpr64 = COPY $x1
%0:gpr64common = COPY $x0
%3:gpr64common = ORRXri %2:gpr64, 1600
%4:gpr64common = ADDXri %0:gpr64common, 100, 0
%5:gpr64 = EORXrs %1:gpr64, %4:gpr64common, 8
%6:gpr64 = ADDXrr %5:gpr64, %4:gpr64common
%7:gpr64 = SUBXrr killed %3:gpr64common, killed %6:gpr64
%8:gpr64 = EORXrs killed %7:gpr64, %5:gpr64, 141
$x0 = COPY %8:gpr64
RET_ReallyLR implicit $x0
...
---
# Negative test. The right form can't reduce latency.
# CHECK-LABEL: name: test3
# CHECK: %6:gpr32 = ADDWrr killed %3, %4
# CHECK-NEXT: %7:gpr32 = SUBWrr %5, killed %6
name: test3
registers:
- { id: 0, class: gpr32common }
- { id: 1, class: gpr32 }
- { id: 2, class: gpr32 }
- { id: 3, class: gpr32common }
- { id: 4, class: gpr32common }
- { id: 5, class: gpr32 }
- { id: 6, class: gpr32 }
- { id: 7, class: gpr32 }
- { id: 8, class: gpr32 }
body: |
bb.0:
%2:gpr32 = COPY $w2
%1:gpr32 = COPY $w1
%0:gpr32common = COPY $w0
%3:gpr32common = ORRWri %2:gpr32, 1600
%4:gpr32common = ADDWri %0:gpr32common, 100, 0
%5:gpr32 = EORWrs %1:gpr32, %4:gpr32common, 8
%6:gpr32 = ADDWrr killed %3:gpr32common, %4:gpr32common
%7:gpr32 = SUBWrr %5:gpr32, killed %6:gpr32
%8:gpr32 = EORWrs killed %7:gpr32, %5:gpr32, 141
$w0 = COPY %8:gpr32
RET_ReallyLR implicit $w0
...
---
# Dead define of flag registers should not block transformation.
# CHECK-LABEL: name: test4
# CHECK: [[TMP:%[0-9]+]]:gpr64common = SUBXrr killed %3, %4
# CHECK-NEXT: %7:gpr64 = SUBXrr killed [[TMP]], %5
name: test4
registers:
- { id: 0, class: gpr64common }
- { id: 1, class: gpr64 }
- { id: 2, class: gpr64 }
- { id: 3, class: gpr64common }
- { id: 4, class: gpr64common }
- { id: 5, class: gpr64 }
- { id: 6, class: gpr64 }
- { id: 7, class: gpr64 }
- { id: 8, class: gpr64 }
body: |
bb.0:
%2:gpr64 = COPY $x2
%1:gpr64 = COPY $x1
%0:gpr64common = COPY $x0
%3:gpr64common = ORRXri %2:gpr64, 1600
%4:gpr64common = ADDXri %0:gpr64common, 100, 0
%5:gpr64 = EORXrs %1:gpr64, %4:gpr64common, 8
%6:gpr64 = ADDSXrr %5:gpr64, %4:gpr64common, implicit-def dead $nzcv
%7:gpr64 = SUBSXrr killed %3:gpr64common, killed %6:gpr64, implicit-def dead $nzcv
%8:gpr64 = EORXrs killed %7:gpr64, %5:gpr64, 141
$x0 = COPY %8:gpr64
RET_ReallyLR implicit $x0
...
---
# Non dead define of flag register in SUB can block the transformation.
# CHECK-LABEL: name: test5
# CHECK: %6:gpr32 = ADDWrr %5, %4
# CHECK-NEXT: %7:gpr32 = SUBSWrr killed %3, killed %6, implicit-def $nzcv
name: test5
registers:
- { id: 0, class: gpr32common }
- { id: 1, class: gpr32 }
- { id: 2, class: gpr32 }
- { id: 3, class: gpr32common }
- { id: 4, class: gpr32common }
- { id: 5, class: gpr32 }
- { id: 6, class: gpr32 }
- { id: 7, class: gpr32 }
- { id: 8, class: gpr32 }
body: |
bb.0:
%2:gpr32 = COPY $w2
%1:gpr32 = COPY $w1
%0:gpr32common = COPY $w0
%3:gpr32common = ORRWri %2:gpr32, 1600
%4:gpr32common = ADDWri %0:gpr32common, 100, 0
%5:gpr32 = EORWrs %1:gpr32, %4:gpr32common, 8
%6:gpr32 = ADDWrr %5:gpr32, %4:gpr32common
%7:gpr32 = SUBSWrr killed %3:gpr32common, killed %6:gpr32, implicit-def $nzcv
%8:gpr32 = EORWrs killed %7:gpr32, %5:gpr32, 141
$w0 = COPY %8:gpr32
RET_ReallyLR implicit $w0
...
---
# Non dead define of flag register in ADD can block the transformation.
# CHECK-LABEL: name: test6
# CHECK: %6:gpr64 = ADDSXrr %5, %4, implicit-def $nzcv
# CHECK-NEXT: %7:gpr64 = SUBXrr killed %3, killed %6
name: test6
registers:
- { id: 0, class: gpr64common }
- { id: 1, class: gpr64 }
- { id: 2, class: gpr64 }
- { id: 3, class: gpr64common }
- { id: 4, class: gpr64common }
- { id: 5, class: gpr64 }
- { id: 6, class: gpr64 }
- { id: 7, class: gpr64 }
- { id: 8, class: gpr64 }
body: |
bb.0:
%2:gpr64 = COPY $x2
%1:gpr64 = COPY $x1
%0:gpr64common = COPY $x0
%3:gpr64common = ORRXri %2:gpr64, 1600
%4:gpr64common = ADDXri %0:gpr64common, 100, 0
%5:gpr64 = EORXrs %1:gpr64, %4:gpr64common, 8
%6:gpr64 = ADDSXrr %5:gpr64, %4:gpr64common, implicit-def $nzcv
%7:gpr64 = SUBXrr killed %3:gpr64common, killed %6:gpr64
%8:gpr64 = EORXrs killed %7:gpr64, %5:gpr64, 141
$x0 = COPY %8:gpr64
RET_ReallyLR implicit $x0
...
---
# ADD has multiple uses, so it is always required, we should not transform it.
# CHECK-LABEL: name: test7
# CHECK: %6:gpr32 = ADDWrr %5, %4
# CHECK-NEXT: %7:gpr32 = SUBWrr killed %3, %6
name: test7
registers:
- { id: 0, class: gpr32common }
- { id: 1, class: gpr32 }
- { id: 2, class: gpr32 }
- { id: 3, class: gpr32common }
- { id: 4, class: gpr32common }
- { id: 5, class: gpr32 }
- { id: 6, class: gpr32 }
- { id: 7, class: gpr32 }
- { id: 8, class: gpr32 }
- { id: 9, class: gpr32 }
body: |
bb.0:
%2:gpr32 = COPY $w2
%1:gpr32 = COPY $w1
%0:gpr32common = COPY $w0
%3:gpr32common = ORRWri %2:gpr32, 1600
%4:gpr32common = ADDWri %0:gpr32common, 100, 0
%5:gpr32 = EORWrs %1:gpr32, %4:gpr32common, 8
%6:gpr32 = ADDWrr %5:gpr32, %4:gpr32common
%7:gpr32 = SUBWrr killed %3:gpr32common, %6:gpr32
%8:gpr32 = EORWrs killed %7:gpr32, %5:gpr32, 141
%9:gpr32 = ADDWrr %8:gpr32, %6:gpr32
$w0 = COPY %9:gpr32
RET_ReallyLR implicit $w0
...
|