1+ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
12; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s
23
34; Transform "a == C ? C : x" to "a == C ? a : x" to avoid materializing C.
4- ; CHECK-LABEL: test1:
5- ; CHECK: cmp w[[REG1:[0-9]+]], #2
6- ; CHECK: mov w[[REG2:[0-9]+]], #7
7- ; CHECK: csel w0, w[[REG1]], w[[REG2]], eq
85define i32 @test1 (i32 %x ) {
6+ ; CHECK-LABEL: test1:
7+ ; CHECK: // %bb.0:
8+ ; CHECK-NEXT: cmp w0, #2
9+ ; CHECK-NEXT: mov w8, #7
10+ ; CHECK-NEXT: csel w0, w0, w8, eq
11+ ; CHECK-NEXT: ret
912 %cmp = icmp eq i32 %x , 2
1013 %res = select i1 %cmp , i32 2 , i32 7
1114 ret i32 %res
1215}
1316
1417; Transform "a == C ? C : x" to "a == C ? a : x" to avoid materializing C.
15- ; CHECK-LABEL: test2:
16- ; CHECK: cmp x[[REG1:[0-9]+]], #2
17- ; CHECK: mov w[[REG2:[0-9]+]], #7
18- ; CHECK: csel x0, x[[REG1]], x[[REG2]], eq
1918define i64 @test2 (i64 %x ) {
19+ ; CHECK-LABEL: test2:
20+ ; CHECK: // %bb.0:
21+ ; CHECK-NEXT: cmp x0, #2
22+ ; CHECK-NEXT: mov w8, #7
23+ ; CHECK-NEXT: csel x0, x0, x8, eq
24+ ; CHECK-NEXT: ret
2025 %cmp = icmp eq i64 %x , 2
2126 %res = select i1 %cmp , i64 2 , i64 7
2227 ret i64 %res
2328}
2429
2530; Transform "a != C ? x : C" to "a != C ? x : a" to avoid materializing C.
26- ; CHECK-LABEL: test3:
27- ; CHECK: cmp x[[REG1:[0-9]+]], #7
28- ; CHECK: mov w[[REG2:[0-9]+]], #2
29- ; CHECK: csel x0, x[[REG2]], x[[REG1]], ne
3031define i64 @test3 (i64 %x ) {
32+ ; CHECK-LABEL: test3:
33+ ; CHECK: // %bb.0:
34+ ; CHECK-NEXT: cmp x0, #7
35+ ; CHECK-NEXT: mov w8, #2
36+ ; CHECK-NEXT: csel x0, x8, x0, ne
37+ ; CHECK-NEXT: ret
3138 %cmp = icmp ne i64 %x , 7
3239 %res = select i1 %cmp , i64 2 , i64 7
3340 ret i64 %res
3441}
3542
3643; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == 0. If we did we
3744; would needlessly extend the live range of x0 when we can just use xzr.
38- ; CHECK-LABEL: test4:
39- ; CHECK: cmp x0, #0
40- ; CHECK: mov w8, #7
41- ; CHECK: csel x0, xzr, x8, eq
4245define i64 @test4 (i64 %x ) {
46+ ; CHECK-LABEL: test4:
47+ ; CHECK: // %bb.0:
48+ ; CHECK-NEXT: cmp x0, #0
49+ ; CHECK-NEXT: mov w8, #7
50+ ; CHECK-NEXT: csel x0, xzr, x8, eq
51+ ; CHECK-NEXT: ret
4352 %cmp = icmp eq i64 %x , 0
4453 %res = select i1 %cmp , i64 0 , i64 7
4554 ret i64 %res
@@ -48,11 +57,13 @@ define i64 @test4(i64 %x) {
4857; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == 1. If we did we
4958; would needlessly extend the live range of x0 when we can just use xzr with
5059; CSINC to materialize the 1.
51- ; CHECK-LABEL: test5:
52- ; CHECK: cmp x0, #1
53- ; CHECK: mov w[[REG:[0-9]+]], #7
54- ; CHECK: csinc x0, x[[REG]], xzr, ne
5560define i64 @test5 (i64 %x ) {
61+ ; CHECK-LABEL: test5:
62+ ; CHECK: // %bb.0:
63+ ; CHECK-NEXT: cmp x0, #1
64+ ; CHECK-NEXT: mov w8, #7
65+ ; CHECK-NEXT: csinc x0, x8, xzr, ne
66+ ; CHECK-NEXT: ret
5667 %cmp = icmp eq i64 %x , 1
5768 %res = select i1 %cmp , i64 1 , i64 7
5869 ret i64 %res
@@ -61,49 +72,59 @@ define i64 @test5(i64 %x) {
6172; Don't transform "a == C ? C : x" to "a == C ? a : x" if a == -1. If we did we
6273; would needlessly extend the live range of x0 when we can just use xzr with
6374; CSINV to materialize the -1.
64- ; CHECK-LABEL: test6:
65- ; CHECK: cmn x0, #1
66- ; CHECK: mov w[[REG:[0-9]+]], #7
67- ; CHECK: csinv x0, x[[REG]], xzr, ne
6875define i64 @test6 (i64 %x ) {
76+ ; CHECK-LABEL: test6:
77+ ; CHECK: // %bb.0:
78+ ; CHECK-NEXT: cmn x0, #1
79+ ; CHECK-NEXT: mov w8, #7
80+ ; CHECK-NEXT: csinv x0, x8, xzr, ne
81+ ; CHECK-NEXT: ret
6982 %cmp = icmp eq i64 %x , -1
7083 %res = select i1 %cmp , i64 -1 , i64 7
7184 ret i64 %res
7285}
7386
74- ; CHECK-LABEL: test7:
75- ; CHECK: cmp x[[REG:[0-9]]], #7
76- ; CHECK: csinc x0, x[[REG]], xzr, eq
7787define i64 @test7 (i64 %x ) {
88+ ; CHECK-LABEL: test7:
89+ ; CHECK: // %bb.0:
90+ ; CHECK-NEXT: cmp x0, #7
91+ ; CHECK-NEXT: csinc x0, x0, xzr, eq
92+ ; CHECK-NEXT: ret
7893 %cmp = icmp eq i64 %x , 7
7994 %res = select i1 %cmp , i64 7 , i64 1
8095 ret i64 %res
8196}
8297
83- ; CHECK-LABEL: test8:
84- ; CHECK: cmp x[[REG:[0-9]]], #7
85- ; CHECK: csinc x0, x[[REG]], xzr, eq
8698define i64 @test8 (i64 %x ) {
99+ ; CHECK-LABEL: test8:
100+ ; CHECK: // %bb.0:
101+ ; CHECK-NEXT: cmp x0, #7
102+ ; CHECK-NEXT: csinc x0, x0, xzr, eq
103+ ; CHECK-NEXT: ret
87104 %cmp = icmp ne i64 %x , 7
88105 %res = select i1 %cmp , i64 1 , i64 7
89106 ret i64 %res
90107}
91108
92- ; CHECK-LABEL: test9:
93- ; CHECK: cmp x[[REG:[0-9]]], #7
94- ; CHECK: csinv x0, x[[REG]], xzr, eq
95109define i64 @test9 (i64 %x ) {
110+ ; CHECK-LABEL: test9:
111+ ; CHECK: // %bb.0:
112+ ; CHECK-NEXT: cmp x0, #7
113+ ; CHECK-NEXT: csinv x0, x0, xzr, eq
114+ ; CHECK-NEXT: ret
96115 %cmp = icmp eq i64 %x , 7
97116 %res = select i1 %cmp , i64 7 , i64 -1
98117 ret i64 %res
99118}
100119
101120; Rather than use a CNEG, use a CSINV to transform "a == 1 ? 1 : -1" to
102121; "a == 1 ? a : -1" to avoid materializing a constant.
103- ; CHECK-LABEL: test10:
104- ; CHECK: cmp w[[REG:[0-9]]], #1
105- ; CHECK: csinv w0, w[[REG]], wzr, eq
106122define i32 @test10 (i32 %x ) {
123+ ; CHECK-LABEL: test10:
124+ ; CHECK: // %bb.0:
125+ ; CHECK-NEXT: cmp w0, #1
126+ ; CHECK-NEXT: csinv w0, w0, wzr, eq
127+ ; CHECK-NEXT: ret
107128 %cmp = icmp eq i32 %x , 1
108129 %res = select i1 %cmp , i32 1 , i32 -1
109130 ret i32 %res
0 commit comments