1 Star 0 Fork 10

Ami-zhang/llvm_oc

forked from OpenCloudOS Stream/llvm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-Clear-instructions-not-recorded-in-ErasedInstrs.patch 9.93 KB
一键复制 编辑 原始数据 按行查看 历史
From 5704a77a9e8330aae5b6fe8d57056e992655624c Mon Sep 17 00:00:00 2001
From: doupengda <[email protected]>
Date: Thu, 5 Sep 2024 19:28:44 +0800
Subject: [PATCH] Clear instructions not recorded in ErasedInstrs
---
llvm/lib/CodeGen/RegisterCoalescer.cpp | 28 ++-
.../register-coalescer-crash-pr79718.mir | 194 ++++++++++++++++++
2 files changed, 216 insertions(+), 6 deletions(-)
create mode 100644 test/CodeGen/LoongArch/register-coalescer-crash-pr79718.mir
diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp
index e49885b6..511a7630 100644
--- a/llvm/lib/CodeGen/RegisterCoalescer.cpp
+++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp
@@ -236,8 +236,8 @@ namespace {
/// was successfully coalesced away. If it is not currently possible to
/// coalesce this interval, but it may be possible if other things get
/// coalesced, then it returns true by reference in 'Again'.
- bool joinCopy(MachineInstr *CopyMI, bool &Again);
-
+ bool joinCopy(MachineInstr *CopyMI, bool &Again,
+ SmallPtrSetImpl<MachineInstr *> &CurrentErasedInstrs);
/// Attempt to join these two intervals. On failure, this
/// returns false. The output "SrcInt" will not have been modified, so we
/// can use this information below to update aliases.
@@ -1899,7 +1899,9 @@ void RegisterCoalescer::setUndefOnPrunedSubRegUses(LiveInterval &LI,
LIS->shrinkToUses(&LI);
}
-bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
+bool RegisterCoalescer::joinCopy(
+ MachineInstr *CopyMI, bool &Again,
+ SmallPtrSetImpl<MachineInstr *> &CurrentErasedInstrs) {
Again = false;
LLVM_DEBUG(dbgs() << LIS->getInstructionIndex(*CopyMI) << '\t' << *CopyMI);
@@ -2091,7 +2093,9 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
// CopyMI has been erased by joinIntervals at this point. Remove it from
// ErasedInstrs since copyCoalesceWorkList() won't add a successful join back
// to the work list. This keeps ErasedInstrs from growing needlessly.
- ErasedInstrs.erase(CopyMI);
+ if (ErasedInstrs.erase(CopyMI))
+ // But we may encounter the instruction again in this iteration.
+ CurrentErasedInstrs.insert(CopyMI);
// Rewrite all SrcReg operands to DstReg.
// Also update DstReg operands to include DstIdx if it is set.
@@ -3915,21 +3919,33 @@ void RegisterCoalescer::lateLiveIntervalUpdate() {
bool RegisterCoalescer::
copyCoalesceWorkList(MutableArrayRef<MachineInstr*> CurrList) {
bool Progress = false;
+ SmallPtrSet<MachineInstr *, 4> CurrentErasedInstrs;
for (MachineInstr *&MI : CurrList) {
if (!MI)
continue;
// Skip instruction pointers that have already been erased, for example by
// dead code elimination.
- if (ErasedInstrs.count(MI)) {
+ if (ErasedInstrs.count(MI) || CurrentErasedInstrs.count(MI)) {
MI = nullptr;
continue;
}
bool Again = false;
- bool Success = joinCopy(MI, Again);
+ bool Success = joinCopy(MI, Again, CurrentErasedInstrs);
Progress |= Success;
if (Success || !Again)
MI = nullptr;
}
+ // Clear instructions not recorded in `ErasedInstrs` but erased.
+ if (!CurrentErasedInstrs.empty()) {
+ for (MachineInstr *&MI : CurrList) {
+ if (MI && CurrentErasedInstrs.count(MI))
+ MI = nullptr;
+ }
+ for (MachineInstr *&MI : WorkList) {
+ if (MI && CurrentErasedInstrs.count(MI))
+ MI = nullptr;
+ }
+ }
return Progress;
}
diff --git a/llvm/test/CodeGen/LoongArch/register-coalescer-crash-pr79718.mir b/llvmtest/CodeGen/LoongArch/register-coalescer-crash-pr79718.mir
new file mode 100644
index 00000000..2776d1a5
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/register-coalescer-crash-pr79718.mir
@@ -0,0 +1,194 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
+# RUN: llc -o - %s -mtriple=loongarch64 \
+# RUN: -run-pass=register-coalescer -join-liveintervals=1 -join-splitedges=0 | FileCheck %s
+
+---
+name: foo
+tracksRegLiveness: true
+body: |
+ ; CHECK-LABEL: name: foo
+ ; CHECK: bb.0:
+ ; CHECK-NEXT: successors: %bb.1(0x80000000)
+ ; CHECK-NEXT: liveins: $r4, $r5, $r6, $r7, $r8
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $r8
+ ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $r7
+ ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $r6
+ ; CHECK-NEXT: [[COPY3:%[0-9]+]]:gpr = COPY $r5
+ ; CHECK-NEXT: [[COPY4:%[0-9]+]]:gpr = COPY $r4
+ ; CHECK-NEXT: [[ANDI:%[0-9]+]]:gpr = ANDI [[COPY3]], 1
+ ; CHECK-NEXT: [[ORI:%[0-9]+]]:gpr = ORI $r0, 1
+ ; CHECK-NEXT: [[ANDI1:%[0-9]+]]:gpr = ANDI [[COPY2]], 1
+ ; CHECK-NEXT: [[ANDI2:%[0-9]+]]:gpr = ANDI [[COPY1]], 1
+ ; CHECK-NEXT: [[ANDI3:%[0-9]+]]:gpr = ANDI [[COPY]], 1
+ ; CHECK-NEXT: [[COPY5:%[0-9]+]]:gpr = COPY $r0
+ ; CHECK-NEXT: [[COPY6:%[0-9]+]]:gpr = COPY $r0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.1:
+ ; CHECK-NEXT: successors: %bb.2(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY7:%[0-9]+]]:gpr = COPY [[COPY5]]
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.2:
+ ; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.4(0x40000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: BEQZ [[ANDI]], %bb.4
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.3:
+ ; CHECK-NEXT: successors: %bb.9(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: PseudoBR %bb.9
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.4:
+ ; CHECK-NEXT: successors: %bb.5(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.5:
+ ; CHECK-NEXT: successors: %bb.7(0x7c000000), %bb.6(0x04000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: dead [[LD_D:%[0-9]+]]:gpr = LD_D $r0, 8
+ ; CHECK-NEXT: dead [[LD_D1:%[0-9]+]]:gpr = LD_D $r0, 0
+ ; CHECK-NEXT: BNEZ [[ANDI1]], %bb.7
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.6:
+ ; CHECK-NEXT: successors: %bb.11(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY6:%[0-9]+]]:gpr = COPY $r0
+ ; CHECK-NEXT: PseudoBR %bb.11
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.7:
+ ; CHECK-NEXT: successors: %bb.8(0x7c000000), %bb.10(0x04000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: BEQZ [[ANDI2]], %bb.10
+ ; CHECK-NEXT: PseudoBR %bb.8
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.8:
+ ; CHECK-NEXT: successors: %bb.9(0x04000000), %bb.5(0x7c000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY6:%[0-9]+]]:gpr = ADDI_D [[COPY6]], 1
+ ; CHECK-NEXT: BEQZ [[ANDI3]], %bb.5
+ ; CHECK-NEXT: PseudoBR %bb.9
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.9:
+ ; CHECK-NEXT: successors: %bb.12(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: ST_B $r0, [[COPY4]], 0
+ ; CHECK-NEXT: PseudoBR %bb.12
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.10:
+ ; CHECK-NEXT: successors: %bb.11(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: [[COPY5:%[0-9]+]]:gpr = ADDI_D [[COPY6]], 1
+ ; CHECK-NEXT: [[COPY6:%[0-9]+]]:gpr = COPY [[ORI]]
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.11:
+ ; CHECK-NEXT: successors: %bb.12(0x80000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: ST_D $r0, [[COPY4]], 0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: bb.12:
+ ; CHECK-NEXT: successors: %bb.2(0x7c000000), %bb.1(0x04000000)
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: BEQ [[COPY7]], [[ORI]], %bb.2
+ ; CHECK-NEXT: PseudoBR %bb.1
+ bb.0:
+ liveins: $r4, $r5, $r6, $r7, $r8
+ %0:gpr = COPY killed $r8
+ %1:gpr = COPY killed $r7
+ %2:gpr = COPY killed $r6
+ %3:gpr = COPY killed $r5
+ %4:gpr = COPY killed $r4
+ %5:gpr = COPY $r0
+ %6:gpr = COPY killed %5
+ %7:gpr = ANDI killed %3, 1
+ %8:gpr = ORI $r0, 1
+ %9:gpr = ANDI killed %2, 1
+ %10:gpr = ANDI killed %1, 1
+ %11:gpr = ANDI killed %0, 1
+ %12:gpr = COPY %6
+ %13:gpr = COPY killed %6
+ %14:gpr = IMPLICIT_DEF
+ bb.1:
+ %15:gpr = COPY killed %14
+ %16:gpr = COPY killed %13
+ %17:gpr = COPY killed %12
+ %18:gpr = COPY %17
+ %19:gpr = COPY %16
+ %20:gpr = COPY killed %16
+ %21:gpr = COPY killed %15
+ bb.2:
+ successors: %bb.3, %bb.4
+ %22:gpr = COPY killed %21
+ %23:gpr = COPY killed %20
+ %24:gpr = COPY killed %19
+ %25:gpr = COPY killed %18
+ BEQZ %7, %bb.4
+ bb.3:
+ %26:gpr = COPY killed %24
+ %27:gpr = COPY killed %23
+ PseudoBR %bb.9
+ bb.4:
+ %28:gpr = COPY killed %23
+ bb.5:
+ successors: %bb.7(0x7c000000), %bb.6(0x04000000)
+ %29:gpr = COPY killed %28
+ dead %30:gpr = LD_D $r0, 8
+ dead %31:gpr = LD_D $r0, 0
+ BNEZ %9, %bb.7
+ bb.6:
+ %32:gpr = COPY $r0
+ %33:gpr = COPY killed %32
+ %34:gpr = COPY killed %33
+ %35:gpr = COPY killed %22
+ PseudoBR %bb.11
+ bb.7:
+ successors: %bb.8(0x7c000000), %bb.10(0x04000000)
+ BEQZ %10, %bb.10
+ PseudoBR %bb.8
+ bb.8:
+ successors: %bb.9(0x04000000), %bb.5(0x7c000000)
+ %36:gpr = ADDI_D killed %29, 1
+ %28:gpr = COPY %36
+ %26:gpr = COPY %36
+ %27:gpr = COPY killed %36
+ BEQZ %11, %bb.5
+ PseudoBR %bb.9
+ bb.9:
+ %37:gpr = COPY killed %27
+ %38:gpr = COPY killed %26
+ %39:gpr = COPY $r0
+ ST_B killed %39, %4, 0
+ %40:gpr = COPY killed %25
+ %41:gpr = COPY killed %38
+ %42:gpr = COPY killed %37
+ %43:gpr = COPY killed %22
+ PseudoBR %bb.12
+ bb.10:
+ %44:gpr = ADDI_D killed %29, 1
+ %34:gpr = COPY %8
+ %35:gpr = COPY killed %44
+ bb.11:
+ %45:gpr = COPY killed %35
+ %46:gpr = COPY killed %34
+ %47:gpr = COPY $r0
+ ST_D killed %47, %4, 0
+ %40:gpr = COPY %45
+ %41:gpr = COPY %46
+ %42:gpr = COPY killed %46
+ %43:gpr = COPY killed %45
+ bb.12:
+ successors: %bb.2(0x7c000000), %bb.1(0x04000000)
+ %48:gpr = COPY killed %43
+ %49:gpr = COPY killed %42
+ %50:gpr = COPY killed %41
+ %51:gpr = COPY killed %40
+ %12:gpr = COPY %51
+ %13:gpr = COPY %50
+ %14:gpr = COPY %48
+ %18:gpr = COPY killed %51
+ %19:gpr = COPY killed %50
+ %20:gpr = COPY killed %49
+ %21:gpr = COPY killed %48
+ BEQ %17, %8, %bb.2
+ PseudoBR %bb.1
+...
--
2.41.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ami-zhang/llvm_oc.git
[email protected]:ami-zhang/llvm_oc.git
ami-zhang
llvm_oc
llvm_oc
master

搜索帮助