[llvm] SystemZ: Implement copyPhysReg between vr128 and gr128 (PR #90616)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 07:34:29 PDT 2024
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/90616
I have no idea if this is correct and I probably swapped the element ordering somewhere.
>From a48e70d60fa1bdcd252e0873617b935b732749ba Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 30 Apr 2024 16:06:52 +0200
Subject: [PATCH] SystemZ: Implement copyPhysReg between vr128 and gr128
I have no idea if this is correct and I probably swapped the
element ordering somewhere.
---
llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp | 35 ++++++++
.../SystemZ/copy-phys-reg-gr128-to-vr128.mir | 82 +++++++++++++++++++
.../SystemZ/copy-phys-reg-vr128-to-gr128.mir | 76 +++++++++++++++++
3 files changed, 193 insertions(+)
create mode 100644 llvm/test/CodeGen/SystemZ/copy-phys-reg-gr128-to-vr128.mir
create mode 100644 llvm/test/CodeGen/SystemZ/copy-phys-reg-vr128-to-gr128.mir
diff --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
index 6b75c30943b40a..ced7b38a1d717b 100644
--- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
@@ -840,6 +840,41 @@ void SystemZInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
return;
}
+ if (SystemZ::GR128BitRegClass.contains(DestReg) &&
+ SystemZ::VR128BitRegClass.contains(SrcReg)) {
+ MCRegister DestH64 = RI.getSubReg(DestReg, SystemZ::subreg_h64);
+ MCRegister DestL64 = RI.getSubReg(DestReg, SystemZ::subreg_l64);
+
+ BuildMI(MBB, MBBI, DL, get(SystemZ::VLGVG), DestL64)
+ .addReg(SrcReg)
+ .addReg(SystemZ::NoRegister)
+ .addImm(0)
+ .addDef(DestReg, RegState::Implicit);
+ BuildMI(MBB, MBBI, DL, get(SystemZ::VLGVG), DestH64)
+ .addReg(SrcReg, getKillRegState(KillSrc))
+ .addReg(SystemZ::NoRegister)
+ .addImm(1);
+ return;
+ }
+
+ if (SystemZ::VR128BitRegClass.contains(DestReg) &&
+ SystemZ::GR128BitRegClass.contains(SrcReg)) {
+ MCRegister SrcH64 = RI.getSubReg(SrcReg, SystemZ::subreg_h64);
+ MCRegister SrcL64 = RI.getSubReg(SrcReg, SystemZ::subreg_l64);
+
+ BuildMI(MBB, MBBI, DL, get(SystemZ::VLVGG), DestReg)
+ .addReg(DestReg, RegState::Undef)
+ .addReg(SrcH64)
+ .addReg(SystemZ::NoRegister)
+ .addImm(0);
+ BuildMI(MBB, MBBI, DL, get(SystemZ::VLVGG), DestReg)
+ .addReg(DestReg)
+ .addReg(SrcL64)
+ .addReg(SystemZ::NoRegister)
+ .addImm(1);
+ return;
+ }
+
// Everything else needs only one instruction.
unsigned Opcode;
if (SystemZ::GR64BitRegClass.contains(DestReg, SrcReg))
diff --git a/llvm/test/CodeGen/SystemZ/copy-phys-reg-gr128-to-vr128.mir b/llvm/test/CodeGen/SystemZ/copy-phys-reg-gr128-to-vr128.mir
new file mode 100644
index 00000000000000..537d5b2ae0df14
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/copy-phys-reg-gr128-to-vr128.mir
@@ -0,0 +1,82 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
+# RUN: llc -mtriple=s390x-ibm-linux -mcpu=z13 -run-pass=postrapseudos -o - %s | FileCheck %s
+
+---
+name: copy_gr128_to_vr128__r0q_to_v0
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $r0q
+ ; CHECK-LABEL: name: copy_gr128_to_vr128__r0q_to_v0
+ ; CHECK: liveins: $r0q
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $v0 = VLVGG undef $v0, $r0d, $noreg, 0
+ ; CHECK-NEXT: $v0 = VLVGG $v0, $r1d, $noreg, 1
+ ; CHECK-NEXT: Return implicit $v0
+ $v0 = COPY $r0q
+ Return implicit $v0
+...
+
+---
+name: copy_gr128_to_vr128__r0q_to_v0_killed
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $r0q
+ ; CHECK-LABEL: name: copy_gr128_to_vr128__r0q_to_v0_killed
+ ; CHECK: liveins: $r0q
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $v0 = VLVGG undef $v0, $r0d, $noreg, 0
+ ; CHECK-NEXT: $v0 = VLVGG $v0, $r1d, $noreg, 1
+ ; CHECK-NEXT: Return implicit $v0
+ $v0 = COPY killed $r0q
+ Return implicit $v0
+...
+
+---
+name: copy_gr128_to_vr128__r0q_to_v0_undef
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $r0q
+ ; CHECK-LABEL: name: copy_gr128_to_vr128__r0q_to_v0_undef
+ ; CHECK: liveins: $r0q
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $v0 = KILL undef $r0q
+ ; CHECK-NEXT: Return implicit $v0
+ $v0 = COPY undef $r0q
+ Return implicit $v0
+...
+
+---
+name: copy_gr128_to_vr128__r0q_to_v0_subreg0
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $r0d
+ ; CHECK-LABEL: name: copy_gr128_to_vr128__r0q_to_v0_subreg0
+ ; CHECK: liveins: $r0d
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $v0 = VLVGG undef $v0, $r0d, $noreg, 0
+ ; CHECK-NEXT: $v0 = VLVGG $v0, $r1d, $noreg, 1
+ ; CHECK-NEXT: Return implicit $v0
+ $v0 = COPY $r0q
+ Return implicit $v0
+...
+
+---
+name: copy_gr128_to_vr128__r0q_to_v0_subreg1
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $r1d
+ ; CHECK-LABEL: name: copy_gr128_to_vr128__r0q_to_v0_subreg1
+ ; CHECK: liveins: $r1d
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $v0 = VLVGG undef $v0, $r0d, $noreg, 0
+ ; CHECK-NEXT: $v0 = VLVGG $v0, $r1d, $noreg, 1
+ ; CHECK-NEXT: Return implicit $v0
+ $v0 = COPY $r0q
+ Return implicit $v0
+...
+
diff --git a/llvm/test/CodeGen/SystemZ/copy-phys-reg-vr128-to-gr128.mir b/llvm/test/CodeGen/SystemZ/copy-phys-reg-vr128-to-gr128.mir
new file mode 100644
index 00000000000000..4eccd49cae33bc
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/copy-phys-reg-vr128-to-gr128.mir
@@ -0,0 +1,76 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
+# RUN: llc -mtriple=s390x-ibm-linux -mcpu=z13 -run-pass=postrapseudos -o - %s | FileCheck %s
+
+---
+name: copy_vr128_to_gr128__v0_to_r0q
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $v0
+ ; CHECK-LABEL: name: copy_vr128_to_gr128__v0_to_r0q
+ ; CHECK: liveins: $v0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $r1d = VLGVG $v0, $noreg, 0, implicit-def $r0q
+ ; CHECK-NEXT: $r0d = VLGVG $v0, $noreg, 1
+ ; CHECK-NEXT: Return implicit $r0q
+ $r0q = COPY $v0
+ Return implicit $r0q
+...
+
+---
+name: copy_vr128_to_gr128__v0_to_r0q_killed
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $v0
+ ; CHECK-LABEL: name: copy_vr128_to_gr128__v0_to_r0q_killed
+ ; CHECK: liveins: $v0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $r1d = VLGVG $v0, $noreg, 0, implicit-def $r0q
+ ; CHECK-NEXT: $r0d = VLGVG killed $v0, $noreg, 1
+ ; CHECK-NEXT: Return implicit $r0q
+ $r0q = COPY killed $v0
+ Return implicit $r0q
+...
+
+---
+name: copy_vr128_to_gr128__v0_to_r0q_undef
+tracksRegLiveness: true
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: copy_vr128_to_gr128__v0_to_r0q_undef
+ ; CHECK: liveins: $v0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $r0q = KILL undef $v0
+ ; CHECK-NEXT: Return implicit $r0q
+ $r0q = COPY undef $v0
+ Return implicit $r0q
+...
+
+---
+name: copy_vr128_to_gr128__v0_to_r0q_undef_use_subreg0
+tracksRegLiveness: true
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: copy_vr128_to_gr128__v0_to_r0q_undef_use_subreg0
+ ; CHECK: liveins: $v0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $r0q = KILL undef $v0
+ ; CHECK-NEXT: Return implicit $r0d
+ $r0q = COPY undef $v0
+ Return implicit $r0d
+...
+
+---
+name: copy_vr128_to_gr128__v0_to_r0q_undef_use_subreg1
+tracksRegLiveness: true
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: copy_vr128_to_gr128__v0_to_r0q_undef_use_subreg1
+ ; CHECK: liveins: $v0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: $r0q = KILL undef $v0
+ ; CHECK-NEXT: Return implicit $r1d
+ $r0q = COPY undef $v0
+ Return implicit $r1d
+...
More information about the llvm-commits
mailing list