1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s
4 ; Transform "a == C ? C : x" to "a == C ? a : x" to avoid materializing C.
5 define i32 @test1(i32 %x) {
8 ; CHECK-NEXT: mov w8, #7
9 ; CHECK-NEXT: cmp w0, #2
10 ; CHECK-NEXT: csel w0, w0, w8, eq
12 %cmp = icmp eq i32 %x, 2
13 %res = select i1 %cmp, i32 2, i32 7
17 ; Transform "a == C ? C : x" to "a == C ? a : x" to avoid materializing C.
18 define i64 @test2(i64 %x) {
21 ; CHECK-NEXT: mov w8, #7
22 ; CHECK-NEXT: cmp x0, #2
23 ; CHECK-NEXT: csel x0, x0, x8, eq
25 %cmp = icmp eq i64 %x, 2
26 %res = select i1 %cmp, i64 2, i64 7
30 ; Transform "a != C ? x : C" to "a != C ? x : a" to avoid materializing C.
31 define i64 @test3(i64 %x) {
34 ; CHECK-NEXT: mov w8, #2
35 ; CHECK-NEXT: cmp x0, #7
36 ; CHECK-NEXT: csel x0, x8, x0, ne
38 %cmp = icmp ne i64 %x, 7
39 %res = select i1 %cmp, i64 2, i64 7
43 ; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == 0. If we did we
44 ; would needlessly extend the live range of x0 when we can just use xzr.
45 define i64 @test4(i64 %x) {
48 ; CHECK-NEXT: mov w8, #7
49 ; CHECK-NEXT: cmp x0, #0
50 ; CHECK-NEXT: csel x0, xzr, x8, eq
52 %cmp = icmp eq i64 %x, 0
53 %res = select i1 %cmp, i64 0, i64 7
57 ; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == 1. If we did we
58 ; would needlessly extend the live range of x0 when we can just use xzr with
59 ; CSINC to materialize the 1.
60 define i64 @test5(i64 %x) {
63 ; CHECK-NEXT: mov w8, #7
64 ; CHECK-NEXT: cmp x0, #1
65 ; CHECK-NEXT: csinc x0, x8, xzr, ne
67 %cmp = icmp eq i64 %x, 1
68 %res = select i1 %cmp, i64 1, i64 7
72 ; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == -1. If we did we
73 ; would needlessly extend the live range of x0 when we can just use xzr with
74 ; CSINV to materialize the -1.
75 define i64 @test6(i64 %x) {
78 ; CHECK-NEXT: mov w8, #7
79 ; CHECK-NEXT: cmn x0, #1
80 ; CHECK-NEXT: csinv x0, x8, xzr, ne
82 %cmp = icmp eq i64 %x, -1
83 %res = select i1 %cmp, i64 -1, i64 7
87 define i64 @test7(i64 %x) {
90 ; CHECK-NEXT: cmp x0, #7
91 ; CHECK-NEXT: csinc x0, x0, xzr, eq
93 %cmp = icmp eq i64 %x, 7
94 %res = select i1 %cmp, i64 7, i64 1
98 define i64 @test8(i64 %x) {
101 ; CHECK-NEXT: cmp x0, #7
102 ; CHECK-NEXT: csinc x0, x0, xzr, eq
104 %cmp = icmp ne i64 %x, 7
105 %res = select i1 %cmp, i64 1, i64 7
109 define i64 @test9(i64 %x) {
110 ; CHECK-LABEL: test9:
112 ; CHECK-NEXT: cmp x0, #7
113 ; CHECK-NEXT: csinv x0, x0, xzr, eq
115 %cmp = icmp eq i64 %x, 7
116 %res = select i1 %cmp, i64 7, i64 -1
120 ; Rather than use a CNEG, use a CSINV to transform "a == 1 ? 1 : -1" to
121 ; "a == 1 ? a : -1" to avoid materializing a constant.
122 define i32 @test10(i32 %x) {
123 ; CHECK-LABEL: test10:
125 ; CHECK-NEXT: cmp w0, #1
126 ; CHECK-NEXT: csinv w0, w0, wzr, eq
128 %cmp = icmp eq i32 %x, 1
129 %res = select i1 %cmp, i32 1, i32 -1