Skip to content

[SystemZ] Add check for INIT_UNDEF in getInstSizeInBytes #134661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2025

Conversation

tltao
Copy link
Contributor

@tltao tltao commented Apr 7, 2025

Due to some optimization changes, INIT_UNDEF is making its way to getInstSizeInBytes in llvm/lib/Target/SystemZ/SystemZLongBranch.cpp but we do not have an exception there in the assert. Since INIT_UNDEF is described as being similar to IMPLICIT_DEF and there is a check for IMPLICIT_DEF, it seems logical to also add a check for INIT_UNDEF.

@tltao tltao changed the title Add check for INIT_UNDEF in getInstSizeInBytes [SystemZ] Add check for INIT_UNDEF in getInstSizeInBytes Apr 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-backend-systemz

Author: None (tltao)

Changes

Due to some optimization changes, INIT_UNDEF is making its way to getInstSizeInBytes in llvm/lib/Target/SystemZ/SystemZLongBranch.cpp but we do not have an exception there in the assert. Since INIT_UNDEF is described as being similar to IMPLICIT_DEF and there is a check for IMPLICIT_DEF, it seems logical to also add a check for INIT_UNDEF.


Full diff: https://github.com/llvm/llvm-project/pull/134661.diff

2 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/MachineInstr.h (+1)
  • (modified) llvm/lib/Target/SystemZ/SystemZLongBranch.cpp (+1)
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 ||

@tltao tltao requested review from nikic, redstar and uweigand April 7, 2025 14:45
Copy link

github-actions bot commented Apr 7, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@@ -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; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is common enough to warrant a dedicated accessor.

@uweigand
Copy link
Member

uweigand commented Apr 7, 2025

We probably should be more generic here and check for isMetaInstruction, which would also cover some of the existing special cases. However, INIT_UNDEF isn't currently even marked as isMeta - probably it should be, though.

@tltao
Copy link
Contributor Author

tltao commented Apr 7, 2025

We probably should be more generic here and check for isMetaInstruction, which would also cover some of the existing special cases. However, INIT_UNDEF isn't currently even marked as isMeta - probably it should be, though.

I believe @nikic tried this in the original PR #106744, but ultimately decided against it as it caused more changes. Perhaps a compromise can be to fix it with MI.getOpcode() == TargetOpcode::INIT_UNDEF for now?

@tltao tltao requested a review from nikic April 7, 2025 17:03
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me, but should it also have a test?

Copy link
Member

@uweigand uweigand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@redstar redstar merged commit 1818943 into llvm:main Apr 10, 2025
11 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
Due to some optimization changes, INIT_UNDEF is making its way to
`getInstSizeInBytes` in `llvm/lib/Target/SystemZ/SystemZLongBranch.cpp`
but we do not have an exception there in the assert. Since INIT_UNDEF is
described as being similar to IMPLICIT_DEF and there is a check for
IMPLICIT_DEF, it seems logical to also add a check for INIT_UNDEF.

---------

Co-authored-by: Tony Tao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants