From 0769f5ca156045986654ca3209f4c7183716d483 Mon Sep 17 00:00:00 2001 From: Tony Tao Date: Mon, 7 Apr 2025 10:37:14 -0400 Subject: [PATCH 1/5] Add check for INIT_UNDEF in getInstSizeInBytes --- llvm/include/llvm/CodeGen/MachineInstr.h | 1 + llvm/lib/Target/SystemZ/SystemZLongBranch.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index 102b1eb07358e..cd7b3055ad722 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -1409,6 +1409,7 @@ class MachineInstr } bool isKill() const { return getOpcode() == TargetOpcode::KILL; } bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; } + bool isInitUndef() const { return getOpcode()==TargetOpcode::INIT_UNDEF; } bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM || getOpcode() == TargetOpcode::INLINEASM_BR; diff --git a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp index f19b932f3c731..f0f33c960d822 100644 --- a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp +++ b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp @@ -218,6 +218,7 @@ static unsigned getInstSizeInBytes(const MachineInstr &MI, // These do not have a size: MI.isDebugOrPseudoInstr() || MI.isPosition() || MI.isKill() || MI.isImplicitDef() || MI.getOpcode() == TargetOpcode::MEMBARRIER || + MI.isInitUndef() || // These have a size that may be zero: MI.isInlineAsm() || MI.getOpcode() == SystemZ::STACKMAP || MI.getOpcode() == SystemZ::PATCHPOINT || From 51066169099b5e57c35c05538db83eeea8dc5dc5 Mon Sep 17 00:00:00 2001 From: Tony Tao Date: Mon, 7 Apr 2025 10:54:59 -0400 Subject: [PATCH 2/5] syntax fix --- llvm/include/llvm/CodeGen/MachineInstr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index cd7b3055ad722..f68fd924e014f 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -1408,8 +1408,8 @@ class MachineInstr getOpcode() == TargetOpcode::G_PHI; } bool isKill() const { return getOpcode() == TargetOpcode::KILL; } - bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; } - bool isInitUndef() const { return getOpcode()==TargetOpcode::INIT_UNDEF; } + bool isImplicitDef() const { return getOpcode() == TargetOpcode::IMPLICIT_DEF; } + bool isInitUndef() const { return getOpcode() == TargetOpcode::INIT_UNDEF; } bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM || getOpcode() == TargetOpcode::INLINEASM_BR; From c080f6bdf1a0e1401d53e064cb242735f8ef9d44 Mon Sep 17 00:00:00 2001 From: Tony Tao Date: Mon, 7 Apr 2025 10:58:23 -0400 Subject: [PATCH 3/5] undo syntax fix --- llvm/include/llvm/CodeGen/MachineInstr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index f68fd924e014f..5d4ce8431a9c7 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -1408,7 +1408,7 @@ class MachineInstr getOpcode() == TargetOpcode::G_PHI; } bool isKill() const { return getOpcode() == TargetOpcode::KILL; } - bool isImplicitDef() const { return getOpcode() == TargetOpcode::IMPLICIT_DEF; } + bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; } bool isInitUndef() const { return getOpcode() == TargetOpcode::INIT_UNDEF; } bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM || From 53b0095f3b761ed99b52fdffde3db5a3f1d4a44b Mon Sep 17 00:00:00 2001 From: Tony Tao Date: Mon, 7 Apr 2025 13:03:13 -0400 Subject: [PATCH 4/5] remove accessor --- llvm/include/llvm/CodeGen/MachineInstr.h | 1 - llvm/lib/Target/SystemZ/SystemZLongBranch.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index 5d4ce8431a9c7..102b1eb07358e 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -1409,7 +1409,6 @@ class MachineInstr } bool isKill() const { return getOpcode() == TargetOpcode::KILL; } bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; } - bool isInitUndef() const { return getOpcode() == TargetOpcode::INIT_UNDEF; } bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM || getOpcode() == TargetOpcode::INLINEASM_BR; diff --git a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp index f0f33c960d822..8103bfe5f4f12 100644 --- a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp +++ b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp @@ -218,7 +218,7 @@ static unsigned getInstSizeInBytes(const MachineInstr &MI, // These do not have a size: MI.isDebugOrPseudoInstr() || MI.isPosition() || MI.isKill() || MI.isImplicitDef() || MI.getOpcode() == TargetOpcode::MEMBARRIER || - MI.isInitUndef() || + MI.getOpcode() == TargetOpcode::INIT_UNDEF || // These have a size that may be zero: MI.isInlineAsm() || MI.getOpcode() == SystemZ::STACKMAP || MI.getOpcode() == SystemZ::PATCHPOINT || From 85ab496fa52b7c7e0b2e0a38c37fc6db723deff2 Mon Sep 17 00:00:00 2001 From: Tony Tao Date: Tue, 8 Apr 2025 15:05:09 -0400 Subject: [PATCH 5/5] add mir test --- llvm/test/CodeGen/SystemZ/init-undef.mir | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 llvm/test/CodeGen/SystemZ/init-undef.mir diff --git a/llvm/test/CodeGen/SystemZ/init-undef.mir b/llvm/test/CodeGen/SystemZ/init-undef.mir new file mode 100644 index 0000000000000..101dc6ebf8fd5 --- /dev/null +++ b/llvm/test/CodeGen/SystemZ/init-undef.mir @@ -0,0 +1,17 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5 +# REQUIRES: asserts +# RUN: llc -run-pass systemz-long-branch -mtriple=s390x-ibm-zos -o - %s | FileCheck %s + +# Makes sure INIT_UNDEF does not crash the compiler in systemz-long-branch +--- +name: func0 +body: | + bb.0.entry: + ; CHECK-LABEL: name: func0 + ; CHECK: renamable $r0l = INIT_UNDEF + ; CHECK-NEXT: renamable $r3d = LGFR killed renamable $r0l + ; CHECK-NEXT: frame-destroy Return_XPLINK implicit $r3d + renamable $r0l = INIT_UNDEF + renamable $r3d = LGFR killed renamable $r0l + frame-destroy Return_XPLINK implicit $r3d +...