[llvm] db232de - [AArch64][GlobalISel] Legalize + select v2p0 -> v264 G_PTRTOINT

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 11:02:13 PDT 2021


Author: Jessica Paquette
Date: 2021-08-24T11:02:01-07:00
New Revision: db232de193978771751cfdc251a3fd4fe161bbec

URL: https://github.com/llvm/llvm-project/commit/db232de193978771751cfdc251a3fd4fe161bbec
DIFF: https://github.com/llvm/llvm-project/commit/db232de193978771751cfdc251a3fd4fe161bbec.diff

LOG: [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

Added: 
    llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir

Modified: 
    llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
    llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
    llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
index 8cba57e6f83f9..222cd216b9112 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -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);
       }
     }
 

diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index 4f84f3999cd72..e7512a09a04e7 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -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);
 

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-ptrtoint.mir
new file mode 100644
index 0000000000000..079969f278360
--- /dev/null
+++ b/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
+...

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir
index 07a2a9b78d804..c967d9486c8cf 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-int-ptr-casts.mir
@@ -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 }
 ...
 
 ---
@@ -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
+...


        


More information about the llvm-commits mailing list