[llvm] [MachineVerifier] Allow KILL MI with dangling MMO in MachineVerifier. (PR #114407)
Jonas Paulsson via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 07:02:35 PDT 2024
https://github.com/JonPsson1 created https://github.com/llvm/llvm-project/pull/114407
An optimization pass may change an instruction into a KILL it seems when there is no use for the produced value. In this case the register coalescer did so while leaving the MMO untouched. The MachineVerifier did not accept this, but it seems reasonable that it should.
This patch makes the machine verifier accept dangling MMOs on KILL instructions.
The alternative might be to have the actor always call something like MI->removeAsKill() which also removed the MMO after setting the opcode to KILL.
@arsenm @ellishg @topperc @michaelmaitland
>From b1682acb1caca4c5a77a08c06e807f2a3dcc2e82 Mon Sep 17 00:00:00 2001
From: Jonas Paulsson <paulson1 at linux.ibm.com>
Date: Thu, 31 Oct 2024 14:48:31 +0100
Subject: [PATCH] Allow KILL MI with dangling MMO in MachineVerifier.
---
llvm/lib/CodeGen/MachineVerifier.cpp | 2 +-
.../CodeGen/SystemZ/machine-ver-kill-memop.ll | 30 +++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/SystemZ/machine-ver-kill-memop.ll
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index e2c09fe25d55cd..cc5acccdc8df66 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -2271,7 +2271,7 @@ void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) {
// Check the MachineMemOperands for basic consistency.
for (MachineMemOperand *Op : MI->memoperands()) {
- if (Op->isLoad() && !MI->mayLoad())
+ if (Op->isLoad() && (!MI->mayLoad() && !MI->isKill()))
report("Missing mayLoad flag", MI);
if (Op->isStore() && !MI->mayStore())
report("Missing mayStore flag", MI);
diff --git a/llvm/test/CodeGen/SystemZ/machine-ver-kill-memop.ll b/llvm/test/CodeGen/SystemZ/machine-ver-kill-memop.ll
new file mode 100644
index 00000000000000..b3cbc332f473a3
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/machine-ver-kill-memop.ll
@@ -0,0 +1,30 @@
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z16 -disable-machine-dce \
+; RUN: -verify-machineinstrs -O3
+;
+; Test that this passes the verifier even though a KILL instruction with a
+; dangling memory operand emerges.
+
+define void @fun(ptr %Src, ptr %Dst) {
+ br label %2
+
+2:
+ %3 = load i32, ptr %Src, align 4
+ %4 = freeze i32 %3
+ %5 = icmp eq i32 %4, 0
+ %6 = load i32, ptr poison, align 4
+ %7 = select i1 %5, i32 0, i32 %6
+ %8 = load i32, ptr %Src, align 4
+ %9 = freeze i32 %8
+ %10 = icmp eq i32 %9, 0
+ %11 = load i32, ptr poison, align 4
+ %12 = select i1 %10, i32 0, i32 %11
+ br label %13
+
+13:
+ %14 = phi i32 [ %12, %13 ], [ %7, %2 ]
+ %15 = icmp slt i32 %14, 5
+ %16 = zext i1 %15 to i64
+ %17 = xor i64 poison, %16
+ store i64 %17, ptr %Dst, align 8
+ br label %13
+}
More information about the llvm-commits
mailing list