Skip to content

Commit

Permalink
[AArch64][GlobalISel] Legalize + select v2p0 -> v264 G_PTRTOINT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jessica Paquette committed Aug 24, 2021
1 parent 1275ee3 commit db232de
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Expand Up @@ -3021,7 +3021,7 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
if (Opcode == TargetOpcode::G_PTRTOINT) {
assert(DstTy.isVector() && "Expected an FPR ptrtoint to be a vector");
I.setDesc(TII.get(TargetOpcode::COPY));
return true;
return selectCopy(I, TII, MRI, TRI, RBI);
}
}

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
Expand Up @@ -487,6 +487,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)

getActionDefinitionsBuilder(G_PTRTOINT)
.legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0})
.legalFor({{v2s64, v2p0}})
.maxScalar(0, s64)
.widenScalarToNextPow2(0, /*Min*/ 8);

Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir
@@ -0,0 +1,22 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -march=aarch64 -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s

...
---
name: v2s64_v2p0_legal
tracksRegLiveness: true
body: |
bb.0:
liveins: $q0
; CHECK-LABEL: name: v2s64_v2p0_legal
; CHECK: liveins: $q0
; CHECK: %ptr:_(<2 x p0>) = COPY $q0
; CHECK: %int:_(<2 x s64>) = G_PTRTOINT %ptr(<2 x p0>)
; CHECK: $q0 = COPY %int(<2 x s64>)
; CHECK: RET_ReallyLR implicit $q0
%ptr:_(<2 x p0>) = COPY $q0
%int:_(<2 x s64>) = G_PTRTOINT %ptr(<2 x p0>)
$q0 = COPY %int(<2 x s64>)
RET_ReallyLR implicit $q0
...
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir
Expand Up @@ -11,6 +11,7 @@
define void @ptrtoint_s8_p0() { ret void }
define void @ptrtoint_s1_p0() { ret void }
define void @inttoptr_v2p0_v2s64() { ret void }
define void @ptrtoint_v2s64_v2p0() { ret void }
...

---
Expand Down Expand Up @@ -158,3 +159,22 @@ body: |
$x0 = COPY %3(p0)
RET_ReallyLR implicit $x0
...
...
---
name: ptrtoint_v2s64_v2p0
legalized: true
regBankSelected: true
tracksRegLiveness: true
body: |
bb.0:
liveins: $q0
; CHECK-LABEL: name: ptrtoint_v2s64_v2p0
; CHECK: liveins: $q0
; CHECK: %ptr:fpr128 = COPY $q0
; CHECK: $q0 = COPY %ptr
; CHECK: RET_ReallyLR implicit $q0
%ptr:fpr(<2 x p0>) = COPY $q0
%int:fpr(<2 x s64>) = G_PTRTOINT %ptr(<2 x p0>)
$q0 = COPY %int(<2 x s64>)
RET_ReallyLR implicit $q0
...

0 comments on commit db232de

Please sign in to comment.