[llvm] df2d4bc - [TwoAddressInstruction] Fix ReplacedAllUntiedUses in processTiedPairs
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 7 02:10:19 PDT 2021
Author: Jay Foad
Date: 2021-10-07T10:10:11+01:00
New Revision: df2d4bc4cbc0626364bd4c5fc8203a00fabcd0d5
URL: https://github.com/llvm/llvm-project/commit/df2d4bc4cbc0626364bd4c5fc8203a00fabcd0d5
DIFF: https://github.com/llvm/llvm-project/commit/df2d4bc4cbc0626364bd4c5fc8203a00fabcd0d5.diff
LOG: [TwoAddressInstruction] Fix ReplacedAllUntiedUses in processTiedPairs
Fix the calculation of ReplacedAllUntiedUses when any of the tied defs
are early-clobber. The effect of this is to fix the placement of kill
flags on an instruction like this (from @f2 in
test/CodeGen/SystemZ/asm-18.ll):
INLINEASM &"stepb $1, $2" [attdialect], $0:[regdef-ec:GRH32Bit], def early-clobber %3:grh32bit, $1:[reguse tiedto:$0], killed %4:grh32bit(tied-def 3), $2:[reguse:GRH32Bit], %4:grh32bit
After TwoAddressInstruction without this patch:
%3:grh32bit = COPY killed %4:grh32bit
INLINEASM &"stepb $1, $2" [attdialect], $0:[regdef-ec:GRH32Bit], def early-clobber %3:grh32bit, $1:[reguse tiedto:$0], %3:grh32bit(tied-def 3), $2:[reguse:GRH32Bit], %4:grh32bit
Note that the COPY kills %4, even though there is a later use of %4 in
the INLINEASM. This fails machine verification if you force it to run
after TwoAddressInstruction (currently it is disabled for other
reasons).
After TwoAddressInstruction with this patch:
%3:grh32bit = COPY %4:grh32bit
INLINEASM &"stepb $1, $2" [attdialect], $0:[regdef-ec:GRH32Bit], def early-clobber %3:grh32bit, $1:[reguse tiedto:$0], %3:grh32bit(tied-def 3), $2:[reguse:GRH32Bit], %4:grh32bit
Differential Revision: https://reviews.llvm.org/D110848
Added:
Modified:
llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
llvm/test/CodeGen/SystemZ/twoaddr-kill.mir
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index 94b456895e00..9896ee7d0ee5 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -1485,9 +1485,10 @@ TwoAddressInstructionPass::processTiedPairs(MachineInstr *MI,
}
if (AllUsesCopied) {
- bool ReplacedAllUntiedUses = true;
+ bool ReplacedAllUntiedUses = false;
if (!IsEarlyClobber) {
// Replace other (un-tied) uses of regB with LastCopiedReg.
+ ReplacedAllUntiedUses = true;
for (MachineOperand &MO : MI->operands()) {
if (MO.isReg() && MO.getReg() == RegB && MO.isUse()) {
if (MO.getSubReg() == SubRegB) {
diff --git a/llvm/test/CodeGen/SystemZ/twoaddr-kill.mir b/llvm/test/CodeGen/SystemZ/twoaddr-kill.mir
index 290f277d100a..7fc7bd3e347b 100644
--- a/llvm/test/CodeGen/SystemZ/twoaddr-kill.mir
+++ b/llvm/test/CodeGen/SystemZ/twoaddr-kill.mir
@@ -1,8 +1,8 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -o - %s -verify-machineinstrs -mtriple=s390x-linux-gnu -mcpu=z196 -run-pass=livevars,twoaddressinstruction | FileCheck %s
-# FIXME: The COPY from [[COPY3]] is killed even though there is a subsequent use
-# of [[COPY3]] in the INLINEASM instruction.
+# Check that the COPY from [[COPY3]] is not killed because there is a subsequent
+# use of [[COPY3]] in the INLINEASM instruction.
---
name: f2
tracksRegLiveness: true
@@ -20,7 +20,7 @@ body: |
; CHECK-NEXT: [[COPY2:%[0-9]+]]:grh32bit = COPY killed [[COPY1]]
; CHECK-NEXT: INLINEASM &"stepa $1, $2, $3", 0 /* attdialect */, 393226 /* regdef:GRH32Bit */, def [[COPY2]], 2147483657 /* reguse tiedto:$0 */, [[COPY2]](tied-def 3), 9 /* reguse */, killed $r2l, 9 /* reguse */, killed $r3l
; CHECK-NEXT: [[COPY3:%[0-9]+]]:grh32bit = COPY killed [[COPY2]]
- ; CHECK-NEXT: [[COPY4:%[0-9]+]]:grh32bit = COPY killed [[COPY3]]
+ ; CHECK-NEXT: [[COPY4:%[0-9]+]]:grh32bit = COPY [[COPY3]]
; CHECK-NEXT: INLINEASM &"stepb $1, $2", 0 /* attdialect */, 393227 /* regdef-ec:GRH32Bit */, def early-clobber [[COPY4]], 2147483657 /* reguse tiedto:$0 */, [[COPY4]](tied-def 3), 393225 /* reguse:GRH32Bit */, [[COPY3]]
; CHECK-NEXT: $r2l = COPY killed [[COPY4]]
; CHECK-NEXT: Return implicit killed $r2l
More information about the llvm-commits
mailing list