# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple aarch64 -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s
...
---
# (x + y) - y -> x
name: simplify_to_x
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_x
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(s32) = COPY $w0
; CHECK-NEXT: $w0 = COPY %x(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x, %y
%sub:_(s32) = G_SUB %add, %y
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# (x + y) - x -> y
name: simplify_to_y
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_y
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: $w0 = COPY %y(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x, %y
%sub:_(s32) = G_SUB %add, %x
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# (x + 1) - 1 -> x
name: simplify_to_constant_x
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_constant_x
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(s32) = COPY $w0
; CHECK-NEXT: $w0 = COPY %x(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y1:_(s32) = G_CONSTANT i32 1
%y2:_(s32) = G_CONSTANT i32 1
%add:_(s32) = G_ADD %x, %y1
%sub:_(s32) = G_SUB %add, %y2
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# (x + y) - x -> y
name: simplify_to_constant_y
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_constant_y
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: $w0 = COPY %y(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x1:_(s32) = G_CONSTANT i32 1
%x2:_(s32) = G_CONSTANT i32 1
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x1, %y
%sub:_(s32) = G_SUB %add, %x2
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# (x + y) - y -> x
name: vector_simplify_to_x
tracksRegLiveness: true
body: |
bb.0:
liveins: $d0, $d1
; CHECK-LABEL: name: vector_simplify_to_x
; CHECK: liveins: $d0, $d1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(<2 x s32>) = COPY $d0
; CHECK-NEXT: $d0 = COPY %x(<2 x s32>)
; CHECK-NEXT: RET_ReallyLR implicit $d0
%x:_(<2 x s32>) = COPY $d0
%y:_(<2 x s32>) = COPY $d1
%add:_(<2 x s32>) = G_ADD %x, %y
%sub:_(<2 x s32>) = G_SUB %add, %y
$d0 = COPY %sub(<2 x s32>)
RET_ReallyLR implicit $d0
...
---
# (x + 1) - 1 -> x
name: splat_simplify_to_x
tracksRegLiveness: true
body: |
bb.0:
liveins: $d0, $d1
; CHECK-LABEL: name: splat_simplify_to_x
; CHECK: liveins: $d0, $d1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(<2 x s32>) = COPY $d0
; CHECK-NEXT: $d0 = COPY %x(<2 x s32>)
; CHECK-NEXT: RET_ReallyLR implicit $d0
%x:_(<2 x s32>) = COPY $d0
%cst:_(s32) = G_CONSTANT i32 1
%y1:_(<2 x s32>) = G_BUILD_VECTOR %cst, %cst
%y2:_(<2 x s32>) = G_BUILD_VECTOR %cst, %cst
%add:_(<2 x s32>) = G_ADD %x, %y1
%sub:_(<2 x s32>) = G_SUB %add, %y2
$d0 = COPY %sub(<2 x s32>)
RET_ReallyLR implicit $d0
...
---
# (x + y) - x -> y
name: unique_registers_no_fold
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1, $w2
; CHECK-LABEL: name: unique_registers_no_fold
; CHECK: liveins: $w0, $w1, $w2
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(s32) = COPY $w0
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: %z:_(s32) = COPY $w2
; CHECK-NEXT: %add:_(s32) = G_ADD %y, %x
; CHECK-NEXT: %sub:_(s32) = G_SUB %add, %z
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y:_(s32) = COPY $w1
%z:_(s32) = COPY $w2
%add:_(s32) = G_ADD %y, %x
%sub:_(s32) = G_SUB %add, %z
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# (x + y) - x -> y
name: unique_constants_no_fold
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: unique_constants_no_fold
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 -1
; CHECK-NEXT: %sub:_(s32) = G_ADD %y, [[C]]
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x1:_(s32) = G_CONSTANT i32 1
%x2:_(s32) = G_CONSTANT i32 2
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x1, %y
%sub:_(s32) = G_SUB %add, %x2
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# x - (y + x) -> 0 - y
name: simplify_to_neg_y
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_neg_y
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: %sub:_(s32) = G_SUB [[C]], %y
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x, %y
%sub:_(s32) = G_SUB %x, %add
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# y - (y + x) -> 0 - x
name: simplify_to_neg_x
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_neg_x
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(s32) = COPY $w0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: %sub:_(s32) = G_SUB [[C]], %x
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x, %y
%sub:_(s32) = G_SUB %y, %add
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# x - (y + x) -> 0 - y
name: simplify_to_neg_y_constant
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_neg_y_constant
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: %sub:_(s32) = G_SUB [[C]], %y
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x1:_(s32) = G_CONSTANT i32 1
%x2:_(s32) = G_CONSTANT i32 1
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x1, %y
%sub:_(s32) = G_SUB %x2, %add
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# y - (y + x) -> 0 - x
name: simplify_to_neg_x_constant
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: simplify_to_neg_x_constant
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(s32) = COPY $w0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: %sub:_(s32) = G_SUB [[C]], %x
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y1:_(s32) = G_CONSTANT i32 1
%y2:_(s32) = G_CONSTANT i32 1
%add:_(s32) = G_ADD %x, %y1
%sub:_(s32) = G_SUB %y2, %add
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# y - (y + x) -> 0 - x
name: vector_simplify_to_neg_x
tracksRegLiveness: true
body: |
bb.0:
liveins: $d0, $d1
; CHECK-LABEL: name: vector_simplify_to_neg_x
; CHECK: liveins: $d0, $d1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(<2 x s32>) = COPY $d0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[C]](s32), [[C]](s32)
; CHECK-NEXT: %sub:_(<2 x s32>) = G_SUB [[BUILD_VECTOR]], %x
; CHECK-NEXT: $d0 = COPY %sub(<2 x s32>)
; CHECK-NEXT: RET_ReallyLR implicit $d0
%x:_(<2 x s32>) = COPY $d0
%y:_(<2 x s32>) = COPY $d1
%add:_(<2 x s32>) = G_ADD %x, %y
%sub:_(<2 x s32>) = G_SUB %y, %add
$d0 = COPY %sub(<2 x s32>)
RET_ReallyLR implicit $d0
...
---
# x - (y + x) -> 0 - y
name: vector_simplify_to_neg_y_constant
tracksRegLiveness: true
body: |
bb.0:
liveins: $d0, $d1
; CHECK-LABEL: name: vector_simplify_to_neg_y_constant
; CHECK: liveins: $d0, $d1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %y:_(<2 x s32>) = COPY $d1
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
; CHECK-NEXT: [[BUILD_VECTOR:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[C]](s32), [[C]](s32)
; CHECK-NEXT: %sub:_(<2 x s32>) = G_SUB [[BUILD_VECTOR]], %y
; CHECK-NEXT: $d0 = COPY %sub(<2 x s32>)
; CHECK-NEXT: RET_ReallyLR implicit $d0
%cst:_(s32) = G_CONSTANT i32 1
%x1:_(<2 x s32>) = G_BUILD_VECTOR %cst, %cst
%x2:_(<2 x s32>) = G_BUILD_VECTOR %cst, %cst
%y:_(<2 x s32>) = COPY $d1
%add:_(<2 x s32>) = G_ADD %x1, %y
%sub:_(<2 x s32>) = G_SUB %x2, %add
$d0 = COPY %sub(<2 x s32>)
RET_ReallyLR implicit $d0
...
---
# y - (y + x) -> 0 - x
name: unique_registers_neg_no_fold
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1, $w2
; CHECK-LABEL: name: unique_registers_neg_no_fold
; CHECK: liveins: $w0, $w1, $w2
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x:_(s32) = COPY $w0
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: %z:_(s32) = COPY $w2
; CHECK-NEXT: %add:_(s32) = G_ADD %x, %y
; CHECK-NEXT: %sub:_(s32) = G_SUB %z, %add
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x:_(s32) = COPY $w0
%y:_(s32) = COPY $w1
%z:_(s32) = COPY $w2
%add:_(s32) = G_ADD %x, %y
%sub:_(s32) = G_SUB %z, %add
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0
...
---
# x - (y + x) -> 0 - y
name: wrong_constant_neg_no_fold
tracksRegLiveness: true
body: |
bb.0:
liveins: $w0, $w1
; CHECK-LABEL: name: wrong_constant_neg_no_fold
; CHECK: liveins: $w0, $w1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %x1:_(s32) = G_CONSTANT i32 1
; CHECK-NEXT: %y:_(s32) = COPY $w1
; CHECK-NEXT: %sub:_(s32) = G_SUB %x1, %y
; CHECK-NEXT: $w0 = COPY %sub(s32)
; CHECK-NEXT: RET_ReallyLR implicit $w0
%x1:_(s32) = G_CONSTANT i32 1
%x2:_(s32) = G_CONSTANT i32 2
%y:_(s32) = COPY $w1
%add:_(s32) = G_ADD %x1, %y
%sub:_(s32) = G_SUB %x2, %add
$w0 = COPY %sub(s32)
RET_ReallyLR implicit $w0