Skip to content

Commit 7f7f249

Browse files
authored
[AArch64PostCoalescer] Propagate undef flag after replacing (#163119)
I encountered a compilation crash issue, and after analysis, it was caused by the AArch64PostCoalescerPass, see https://godbolt.org/z/vPeqeo5Pa. When replacing the register, if the source register has undef flag, we should propagate the flag to all uses of the destination register.
1 parent cd24d10 commit 7f7f249

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ yaml::AArch64FunctionInfo::AArch64FunctionInfo(
4040
getSVEStackSize(MFI, &llvm::AArch64FunctionInfo::getStackSizePPR)),
4141
HasStackFrame(MFI.hasStackFrame()
4242
? std::optional<bool>(MFI.hasStackFrame())
43-
: std::nullopt) {}
43+
: std::nullopt),
44+
HasStreamingModeChanges(
45+
MFI.hasStreamingModeChanges()
46+
? std::optional<bool>(MFI.hasStreamingModeChanges())
47+
: std::nullopt) {}
4448

4549
void yaml::AArch64FunctionInfo::mappingImpl(yaml::IO &YamlIO) {
4650
MappingTraits<AArch64FunctionInfo>::mapping(YamlIO, *this);
@@ -55,6 +59,8 @@ void AArch64FunctionInfo::initializeBaseYamlFields(
5559
YamlMFI.StackSizePPR.value_or(0));
5660
if (YamlMFI.HasStackFrame)
5761
setHasStackFrame(*YamlMFI.HasStackFrame);
62+
if (YamlMFI.HasStreamingModeChanges)
63+
setHasStreamingModeChanges(*YamlMFI.HasStreamingModeChanges);
5864
}
5965

6066
static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {

llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
645645
std::optional<uint64_t> StackSizeZPR;
646646
std::optional<uint64_t> StackSizePPR;
647647
std::optional<bool> HasStackFrame;
648+
std::optional<bool> HasStreamingModeChanges;
648649

649650
AArch64FunctionInfo() = default;
650651
AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI);
@@ -659,6 +660,7 @@ template <> struct MappingTraits<AArch64FunctionInfo> {
659660
YamlIO.mapOptional("stackSizeZPR", MFI.StackSizeZPR);
660661
YamlIO.mapOptional("stackSizePPR", MFI.StackSizePPR);
661662
YamlIO.mapOptional("hasStackFrame", MFI.HasStackFrame);
663+
YamlIO.mapOptional("hasStreamingModeChanges", MFI.HasStreamingModeChanges);
662664
}
663665
};
664666

llvm/lib/Target/AArch64/AArch64PostCoalescerPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ bool AArch64PostCoalescer::runOnMachineFunction(MachineFunction &MF) {
7575
if (Src != Dst)
7676
MRI->replaceRegWith(Dst, Src);
7777

78+
if (MI.getOperand(1).isUndef())
79+
for (MachineOperand &MO : MRI->use_operands(Dst))
80+
MO.setIsUndef();
81+
7882
// MI must be erased from the basic block before recalculating the live
7983
// interval.
8084
LIS->RemoveMachineInstrFromMaps(MI);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
2+
# RUN: llc -mtriple=aarch64 -mattr=+sme -run-pass=aarch64-post-coalescer-pass -o - %s | FileCheck %s
3+
4+
---
5+
name: foo
6+
machineFunctionInfo:
7+
hasStreamingModeChanges: true
8+
body: |
9+
bb.0.entry:
10+
; CHECK-LABEL: name: foo
11+
; CHECK: $d0 = COPY undef %0:fpr64
12+
; CHECK-NEXT: FAKE_USE implicit $d0
13+
%1:fpr64 = COALESCER_BARRIER_FPR64 undef %1
14+
$d0 = COPY %1
15+
FAKE_USE implicit $d0
16+
...
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llc -mtriple=aarch64 -mattr=+sme -stop-after=aarch64-isel < %s | FileCheck %s
2+
3+
target triple = "aarch64"
4+
5+
declare void @foo() "aarch64_pstate_sm_enabled"
6+
7+
define dso_local void @bar() local_unnamed_addr {
8+
; CHECK-LABEL: name: bar
9+
; CHECK: hasStreamingModeChanges: true
10+
entry:
11+
tail call void @foo() "aarch64_pstate_sm_enabled"
12+
ret void
13+
}

0 commit comments

Comments
 (0)