[llvm] d3263d3 - TwoAddressInstructions: Don't treat an undef use as a kill (#227309)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 10:47:46 PDT 2026
Author: Matt Arsenault
Date: 2026-09-29T19:47:39+02:00
New Revision: d3263d348e9908efaf128e65f54d6029b6b61036
URL: https://github.com/llvm/llvm-project/commit/d3263d348e9908efaf128e65f54d6029b6b61036
DIFF: https://github.com/llvm/llvm-project/commit/d3263d348e9908efaf128e65f54d6029b6b61036.diff
LOG: TwoAddressInstructions: Don't treat an undef use as a kill (#227309)
An undef use does not read a value, so LiveIntervals does not extend the
live range to cover it. Previously this would hit the assert on an
undef use.
Exposed by #225174, which made LiveIntervals available here by default.
Co-authored-by: Claude Opus 5 <noreply at anthropic.com>
Added:
llvm/test/CodeGen/X86/twoaddr-undef-use-not-killed.mir
Modified:
llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index 9ec96c180a0c1..b48506d970f36 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -400,7 +400,8 @@ bool TwoAddressInstructionImpl::isPlainlyKilled(const MachineInstr *MI,
SlotIndex useIdx = LIS->getInstructionIndex(*MI);
LiveInterval::const_iterator I = LR.find(useIdx);
- assert(I != LR.end() && "Reg must be live-in to use.");
+ if (I == LR.end())
+ return false;
return !I->end.isBlock() && SlotIndex::isSameInstr(I->end, useIdx);
}
diff --git a/llvm/test/CodeGen/X86/twoaddr-undef-use-not-killed.mir b/llvm/test/CodeGen/X86/twoaddr-undef-use-not-killed.mir
new file mode 100644
index 0000000000000..9925c89bb22db
--- /dev/null
+++ b/llvm/test/CodeGen/X86/twoaddr-undef-use-not-killed.mir
@@ -0,0 +1,31 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=x86_64 -run-pass=liveintervals,twoaddressinstruction -o - %s | FileCheck %s
+
+# An undef use does not extend the live range, so %1 is not live at
+# the PMAXUDrr commute candidate and must not be reported as killed
+# there.
+
+---
+name: undef_use_not_killed
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $xmm0
+ ; CHECK-LABEL: name: undef_use_not_killed
+ ; CHECK: liveins: $xmm0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:vr128 = COPY $xmm0
+ ; CHECK-NEXT: [[DEF:%[0-9]+]]:vr128 = IMPLICIT_DEF
+ ; CHECK-NEXT: [[COPY1:%[0-9]+]]:vr128 = COPY [[DEF]]
+ ; CHECK-NEXT: dead [[COPY1:%[0-9]+]]:vr128 = PADDDrr [[COPY1]], [[COPY1]]
+ ; CHECK-NEXT: [[COPY2:%[0-9]+]]:vr128 = COPY [[COPY]]
+ ; CHECK-NEXT: [[COPY2:%[0-9]+]]:vr128 = PMAXUDrr [[COPY2]], undef [[DEF]]
+ ; CHECK-NEXT: $xmm0 = COPY [[COPY2]]
+ ; CHECK-NEXT: RET 0, implicit $xmm0
+ %0:vr128 = COPY $xmm0
+ %1:vr128 = IMPLICIT_DEF
+ %2:vr128 = PADDDrr %1, %1
+ %3:vr128 = PMAXUDrr %0, undef %1
+ $xmm0 = COPY %3
+ RET 0, implicit killed $xmm0
+...
More information about the llvm-commits
mailing list