Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Feb 3, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Feb 3, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm marked this pull request as ready for review February 3, 2025 15:44
@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2025

@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-llvm-regalloc

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/125518.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/TwoAddressInstructionPass.cpp (+3)
  • (added) llvm/test/CodeGen/ARM/twoaddress-asserts-liveints-undef-use.mir (+24)
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index fb6274b09919ba..6236268f77ab16 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -489,6 +489,9 @@ MachineInstr *TwoAddressInstructionImpl::findOnlyInterestingUse(
     bool &IsDstPhys) const {
   MachineOperand *UseOp = nullptr;
   for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
+    if (MO.isUndef())
+      continue;
+
     MachineInstr *MI = MO.getParent();
     if (MI->getParent() != MBB)
       return nullptr;
diff --git a/llvm/test/CodeGen/ARM/twoaddress-asserts-liveints-undef-use.mir b/llvm/test/CodeGen/ARM/twoaddress-asserts-liveints-undef-use.mir
new file mode 100644
index 00000000000000..6e33d4be9345da
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/twoaddress-asserts-liveints-undef-use.mir
@@ -0,0 +1,24 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve -verify-machineinstrs -run-pass=liveintervals,twoaddressinstruction -o - %s | FileCheck %s
+
+---
+name:      undef_use_asserts_lr
+tracksRegLiveness: true
+noPhis:          true
+body:             |
+  bb.0:
+    liveins: $q0
+
+    ; CHECK-LABEL: name: undef_use_asserts_lr
+    ; CHECK: liveins: $q0
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: [[COPY:%[0-9]+]]:mqpr = COPY $q0
+    ; CHECK-NEXT: [[DEF:%[0-9]+]]:spr = IMPLICIT_DEF
+    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:mqpr = COPY [[COPY]]
+    ; CHECK-NEXT: dead [[COPY1:%[0-9]+]].ssub_2:mqpr = COPY [[DEF]]
+    ; CHECK-NEXT: dead [[COPY2:%[0-9]+]]:spr = COPY undef [[COPY1]].ssub_3
+    %0:mqpr = COPY $q0
+    %1:spr = IMPLICIT_DEF
+    %2:mqpr = INSERT_SUBREG %0, %1, %subreg.ssub_2
+    dead %4:spr = COPY undef %2.ssub_3
+...

for (MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
if (MO.isUndef())
continue;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to your patch, but should there be a break after line 499?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should, but I'd need to look exactly at all the implementations of isPlainlyKilled. At least the LiveIntervals one checks there's only one value in the interval

@arsenm arsenm merged commit 3a2b552 into main Feb 3, 2025
13 checks passed
@arsenm arsenm deleted the users/arsenm/two-address-fix-early-liveints-assert-undef-use branch February 3, 2025 16:48
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants