Skip to content

Commit db232de

Browse files
author
Jessica Paquette
committed
[AArch64][GlobalISel] Legalize + select v2p0 -> v264 G_PTRTOINT
1) Just mark this case as legal because it can just be a copy. 2) Ensure the copy in the existing code actually gets selected. Without doing this, we'll crash because the destination won't have a register class. This fell back 35 times in a build of clang with GISel for AArch64. Differential Revision: https://reviews.llvm.org/D108610
1 parent 1275ee3 commit db232de

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
30213021
if (Opcode == TargetOpcode::G_PTRTOINT) {
30223022
assert(DstTy.isVector() && "Expected an FPR ptrtoint to be a vector");
30233023
I.setDesc(TII.get(TargetOpcode::COPY));
3024-
return true;
3024+
return selectCopy(I, TII, MRI, TRI, RBI);
30253025
}
30263026
}
30273027

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
487487

488488
getActionDefinitionsBuilder(G_PTRTOINT)
489489
.legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0})
490+
.legalFor({{v2s64, v2p0}})
490491
.maxScalar(0, s64)
491492
.widenScalarToNextPow2(0, /*Min*/ 8);
492493

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -march=aarch64 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s
3+
4+
...
5+
---
6+
name: v2s64_v2p0_legal
7+
tracksRegLiveness: true
8+
body: |
9+
bb.0:
10+
liveins: $q0
11+
12+
; CHECK-LABEL: name: v2s64_v2p0_legal
13+
; CHECK: liveins: $q0
14+
; CHECK: %ptr:_(<2 x p0>) = COPY $q0
15+
; CHECK: %int:_(<2 x s64>) = G_PTRTOINT %ptr(<2 x p0>)
16+
; CHECK: $q0 = COPY %int(<2 x s64>)
17+
; CHECK: RET_ReallyLR implicit $q0
18+
%ptr:_(<2 x p0>) = COPY $q0
19+
%int:_(<2 x s64>) = G_PTRTOINT %ptr(<2 x p0>)
20+
$q0 = COPY %int(<2 x s64>)
21+
RET_ReallyLR implicit $q0
22+
...

llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
define void @ptrtoint_s8_p0() { ret void }
1212
define void @ptrtoint_s1_p0() { ret void }
1313
define void @inttoptr_v2p0_v2s64() { ret void }
14+
define void @ptrtoint_v2s64_v2p0() { ret void }
1415
...
1516

1617
---
@@ -158,3 +159,22 @@ body: |
158159
$x0 = COPY %3(p0)
159160
RET_ReallyLR implicit $x0
160161
...
162+
...
163+
---
164+
name: ptrtoint_v2s64_v2p0
165+
legalized: true
166+
regBankSelected: true
167+
tracksRegLiveness: true
168+
body: |
169+
bb.0:
170+
liveins: $q0
171+
; CHECK-LABEL: name: ptrtoint_v2s64_v2p0
172+
; CHECK: liveins: $q0
173+
; CHECK: %ptr:fpr128 = COPY $q0
174+
; CHECK: $q0 = COPY %ptr
175+
; CHECK: RET_ReallyLR implicit $q0
176+
%ptr:fpr(<2 x p0>) = COPY $q0
177+
%int:fpr(<2 x s64>) = G_PTRTOINT %ptr(<2 x p0>)
178+
$q0 = COPY %int(<2 x s64>)
179+
RET_ReallyLR implicit $q0
180+
...

0 commit comments

Comments
 (0)