Skip to content

Commit 665da59

Browse files
committed
[AArch64][GlobalISel] Add legalizer & selector support for G_FREEZE.
These should legalize like undefs and select into copies. The ll test is copied from the x86 test, minus the half fp case because we don't currently support that.
1 parent b593bfd commit 665da59

File tree

5 files changed

+225
-3
lines changed

5 files changed

+225
-3
lines changed

llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,8 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
25962596
return true;
25972597
}
25982598

2599+
case TargetOpcode::G_FREEZE:
2600+
return selectCopy(I, TII, MRI, TRI, RBI);
25992601

26002602
case TargetOpcode::G_INTTOPTR:
26012603
// The importer is currently unable to import pointer types since they

llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST) {
5858
return;
5959
}
6060

61-
getActionDefinitionsBuilder(G_IMPLICIT_DEF)
61+
getActionDefinitionsBuilder({G_IMPLICIT_DEF, G_FREEZE})
6262
.legalFor({p0, s1, s8, s16, s32, s64, v2s32, v4s32, v2s64})
6363
.clampScalar(0, s1, s64)
6464
.widenScalarToNextPow2(0, 8)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s 2>&1 | FileCheck %s
3+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -global-isel -global-isel-abort=1 < %s 2>&1 | FileCheck %s --check-prefix=GISEL
4+
5+
%struct.T = type { i32, i32 }
6+
7+
define i32 @freeze_int() {
8+
; CHECK-LABEL: freeze_int:
9+
; CHECK: // %bb.0:
10+
; CHECK-NEXT: mul w0, w8, w8
11+
; CHECK-NEXT: ret
12+
;
13+
; GISEL-LABEL: freeze_int:
14+
; GISEL: // %bb.0:
15+
; GISEL-NEXT: mul w0, w8, w8
16+
; GISEL-NEXT: ret
17+
%y1 = freeze i32 undef
18+
%t1 = mul i32 %y1, %y1
19+
ret i32 %t1
20+
}
21+
22+
define i5 @freeze_int2() {
23+
; CHECK-LABEL: freeze_int2:
24+
; CHECK: // %bb.0:
25+
; CHECK-NEXT: mul w0, w8, w8
26+
; CHECK-NEXT: ret
27+
;
28+
; GISEL-LABEL: freeze_int2:
29+
; GISEL: // %bb.0:
30+
; GISEL-NEXT: mul w0, w8, w8
31+
; GISEL-NEXT: ret
32+
%y1 = freeze i5 undef
33+
%t1 = mul i5 %y1, %y1
34+
ret i5 %t1
35+
}
36+
37+
define float @freeze_float() {
38+
; CHECK-LABEL: freeze_float:
39+
; CHECK: // %bb.0:
40+
; CHECK-NEXT: fadd s0, s0, s0
41+
; CHECK-NEXT: ret
42+
;
43+
; GISEL-LABEL: freeze_float:
44+
; GISEL: // %bb.0:
45+
; GISEL-NEXT: fadd s0, s0, s0
46+
; GISEL-NEXT: ret
47+
%y1 = freeze float undef
48+
%t1 = fadd float %y1, %y1
49+
ret float %t1
50+
}
51+
52+
define <2 x i32> @freeze_ivec() {
53+
; CHECK-LABEL: freeze_ivec:
54+
; CHECK: // %bb.0:
55+
; CHECK-NEXT: add v0.2s, v0.2s, v0.2s
56+
; CHECK-NEXT: ret
57+
;
58+
; GISEL-LABEL: freeze_ivec:
59+
; GISEL: // %bb.0:
60+
; GISEL-NEXT: add v0.2s, v0.2s, v0.2s
61+
; GISEL-NEXT: ret
62+
%y1 = freeze <2 x i32> undef
63+
%t1 = add <2 x i32> %y1, %y1
64+
ret <2 x i32> %t1
65+
}
66+
67+
define i8* @freeze_ptr() {
68+
; CHECK-LABEL: freeze_ptr:
69+
; CHECK: // %bb.0:
70+
; CHECK-NEXT: add x0, x8, #4 // =4
71+
; CHECK-NEXT: ret
72+
;
73+
; GISEL-LABEL: freeze_ptr:
74+
; GISEL: // %bb.0:
75+
; GISEL-NEXT: add x0, x8, #4 // =4
76+
; GISEL-NEXT: ret
77+
%y1 = freeze i8* undef
78+
%t1 = getelementptr i8, i8* %y1, i64 4
79+
ret i8* %t1
80+
}
81+
82+
define i32 @freeze_struct() {
83+
; CHECK-LABEL: freeze_struct:
84+
; CHECK: // %bb.0:
85+
; CHECK-NEXT: add w0, w8, w8
86+
; CHECK-NEXT: ret
87+
;
88+
; GISEL-LABEL: freeze_struct:
89+
; GISEL: // %bb.0:
90+
; GISEL-NEXT: add w0, w8, w8
91+
; GISEL-NEXT: ret
92+
%y1 = freeze %struct.T undef
93+
%v1 = extractvalue %struct.T %y1, 0
94+
%v2 = extractvalue %struct.T %y1, 1
95+
%t1 = add i32 %v1, %v2
96+
ret i32 %t1
97+
}
98+
99+
define i32 @freeze_anonstruct() {
100+
; CHECK-LABEL: freeze_anonstruct:
101+
; CHECK: // %bb.0:
102+
; CHECK-NEXT: add w0, w8, w8
103+
; CHECK-NEXT: ret
104+
;
105+
; GISEL-LABEL: freeze_anonstruct:
106+
; GISEL: // %bb.0:
107+
; GISEL-NEXT: add w0, w8, w8
108+
; GISEL-NEXT: ret
109+
%y1 = freeze {i32, i32} undef
110+
%v1 = extractvalue {i32, i32} %y1, 0
111+
%v2 = extractvalue {i32, i32} %y1, 1
112+
%t1 = add i32 %v1, %v2
113+
ret i32 %t1
114+
}
115+
116+
define i32 @freeze_anonstruct2() {
117+
; CHECK-LABEL: freeze_anonstruct2:
118+
; CHECK: // %bb.0:
119+
; CHECK-NEXT: add w0, w8, w8, uxth
120+
; CHECK-NEXT: ret
121+
;
122+
; GISEL-LABEL: freeze_anonstruct2:
123+
; GISEL: // %bb.0:
124+
; GISEL-NEXT: add w0, w8, w8, uxth
125+
; GISEL-NEXT: ret
126+
%y1 = freeze {i32, i16} undef
127+
%v1 = extractvalue {i32, i16} %y1, 0
128+
%v2 = extractvalue {i32, i16} %y1, 1
129+
%z2 = zext i16 %v2 to i32
130+
%t1 = add i32 %v1, %z2
131+
ret i32 %t1
132+
}
133+
134+
define i64 @freeze_array() {
135+
; CHECK-LABEL: freeze_array:
136+
; CHECK: // %bb.0:
137+
; CHECK-NEXT: add x0, x8, x8
138+
; CHECK-NEXT: ret
139+
;
140+
; GISEL-LABEL: freeze_array:
141+
; GISEL: // %bb.0:
142+
; GISEL-NEXT: add x0, x8, x8
143+
; GISEL-NEXT: ret
144+
%y1 = freeze [2 x i64] undef
145+
%v1 = extractvalue [2 x i64] %y1, 0
146+
%v2 = extractvalue [2 x i64] %y1, 1
147+
%t1 = add i64 %v1, %v2
148+
ret i64 %t1
149+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -march=aarch64 -run-pass=legalizer -O0 %s -o - | FileCheck %s
3+
---
4+
name: test_freeze_s64
5+
body: |
6+
bb.0.entry:
7+
liveins: $x0
8+
9+
; CHECK-LABEL: name: test_freeze_s64
10+
; CHECK: %x0:_(s64) = COPY $x0
11+
; CHECK: [[FREEZE:%[0-9]+]]:_(s64) = G_FREEZE %x0
12+
; CHECK: $x0 = COPY [[FREEZE]](s64)
13+
%x0:_(s64) = COPY $x0
14+
%1:_(s64) = G_FREEZE %x0
15+
$x0 = COPY %1(s64)
16+
...
17+
---
18+
name: test_freeze_v4s32
19+
body: |
20+
bb.0:
21+
liveins: $q0
22+
23+
; CHECK-LABEL: name: test_freeze_v4s32
24+
; CHECK: %q0:_(<4 x s32>) = COPY $q0
25+
; CHECK: [[FREEZE:%[0-9]+]]:_(<4 x s32>) = G_FREEZE %q0
26+
; CHECK: [[UV:%[0-9]+]]:_(<2 x s32>), [[UV1:%[0-9]+]]:_(<2 x s32>) = G_UNMERGE_VALUES [[FREEZE]](<4 x s32>)
27+
; CHECK: $x0 = COPY [[UV]](<2 x s32>)
28+
; CHECK: $x1 = COPY [[UV1]](<2 x s32>)
29+
%q0:_(<4 x s32>) = COPY $q0
30+
%0:_(<4 x s32>) = G_FREEZE %q0
31+
%1:_(<2 x s32> ), %2:_(<2 x s32>) = G_UNMERGE_VALUES %0
32+
$x0 = COPY %1
33+
$x1 = COPY %2
34+
...
35+
---
36+
name: test_freeze_v4s64
37+
body: |
38+
bb.0:
39+
40+
; CHECK-LABEL: name: test_freeze_v4s64
41+
; CHECK: [[DEF:%[0-9]+]]:_(<2 x s64>) = G_IMPLICIT_DEF
42+
; CHECK: [[COPY:%[0-9]+]]:_(<2 x s64>) = COPY [[DEF]](<2 x s64>)
43+
; CHECK: [[FREEZE:%[0-9]+]]:_(<2 x s64>) = G_FREEZE [[DEF]]
44+
; CHECK: [[FREEZE1:%[0-9]+]]:_(<2 x s64>) = G_FREEZE [[COPY]]
45+
; CHECK: $q0 = COPY [[FREEZE]](<2 x s64>)
46+
; CHECK: $q1 = COPY [[FREEZE1]](<2 x s64>)
47+
%undef:_(<4 x s64>) = G_IMPLICIT_DEF
48+
%0:_(<4 x s64>) = G_FREEZE %undef
49+
%1:_(<2 x s64> ), %2:_(<2 x s64>) = G_UNMERGE_VALUES %0
50+
$q0 = COPY %1
51+
$q1 = COPY %2
52+
...
53+
---
54+
name: test_freeze_v2s32
55+
body: |
56+
bb.0:
57+
liveins: $d0
58+
59+
; CHECK-LABEL: name: test_freeze_v2s32
60+
; CHECK: %d0:_(<2 x s32>) = COPY $d0
61+
; CHECK: [[FREEZE:%[0-9]+]]:_(<2 x s32>) = G_FREEZE %d0
62+
; CHECK: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[FREEZE]](<2 x s32>)
63+
; CHECK: $w0 = COPY [[UV]](s32)
64+
; CHECK: $w1 = COPY [[UV1]](s32)
65+
%d0:_(<2 x s32>) = COPY $d0
66+
%0:_(<2 x s32>) = G_FREEZE %d0
67+
%1:_(s32), %2:_(s32) = G_UNMERGE_VALUES %0
68+
$w0 = COPY %1
69+
$w1 = COPY %2
70+
...

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@
117117
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
118118
#
119119
# DEBUG-NEXT: G_FREEZE (opcode {{[0-9]+}}): 1 type index, 0 imm indices
120-
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
121-
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
120+
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
121+
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
122+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
122123
#
123124
# DEBUG-NEXT: G_INTRINSIC_TRUNC (opcode {{[0-9]+}}): 1 type index, 0 imm indices
124125
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}

0 commit comments

Comments
 (0)