Skip to content

[SystemZ] Treat FAKE_USE instructions as instructions without a size #144390

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SLTozer
Copy link
Contributor

@SLTozer SLTozer commented Jun 16, 2025

This patch fixes an error in which FAKE_USE instructions would trigger an assertion in SystemZLongBranch due to them having a size of 0 without being excepted in the assertion that each instruction, other than a set of known 0-size instruction types, should have a non-0 size.

FAKE_USE instructions are no-op instructions that are emitted into LLVM by the -fextend-variable-liveness clang flag to help preserve the liveness of source variables in optimized code, and therefore they should be understood as being valid size 0 instructions.

This patch fixes an error in which FAKE_USE instructions would trigger an
assertion in SystemZLongBranch due to them having a size of 0 without being
excepted in the assertion that each instruction, other than a set of known
0-size instruction types, should have a non-0 size.
@SLTozer SLTozer self-assigned this Jun 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 16, 2025

@llvm/pr-subscribers-backend-systemz

Author: Stephen Tozer (SLTozer)

Changes

This patch fixes an error in which FAKE_USE instructions would trigger an assertion in SystemZLongBranch due to them having a size of 0 without being excepted in the assertion that each instruction, other than a set of known 0-size instruction types, should have a non-0 size.

FAKE_USE instructions are no-op instructions that are emitted into LLVM by the -fextend-variable-liveness clang flag to help preserve the liveness of source variables in optimized code, and therefore they should be understood as being valid size 0 instructions.


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

2 Files Affected:

  • (modified) llvm/lib/Target/SystemZ/SystemZLongBranch.cpp (+1-1)
  • (added) llvm/test/CodeGen/SystemZ/fake-use-size.ll (+14)
diff --git a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
index 54e1eb0954945..21a233b2ffa1d 100644
--- a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
@@ -215,7 +215,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.getOpcode() == TargetOpcode::INIT_UNDEF ||
+          MI.getOpcode() == TargetOpcode::INIT_UNDEF || MI.isFakeUse() ||
           // These have a size that may be zero:
           MI.isInlineAsm() || MI.getOpcode() == SystemZ::STACKMAP ||
           MI.getOpcode() == SystemZ::PATCHPOINT ||
diff --git a/llvm/test/CodeGen/SystemZ/fake-use-size.ll b/llvm/test/CodeGen/SystemZ/fake-use-size.ll
new file mode 100644
index 0000000000000..1690a046aad43
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/fake-use-size.ll
@@ -0,0 +1,14 @@
+; RUN: llc -O0 < %s -mtriple=s390x-linux-gnu 2>&1 | FileCheck %s
+
+;; Tests that we can handle FAKE_USE instructions, emitting a comment for them
+;; in the resulting assembly.
+
+; CHECK:      .type   idd,@function
+; CHECK:      # %bb.0:
+; CHECK-NEXT: # fake_use:
+
+define double @idd(double %d) {
+entry:
+  notail call void (...) @llvm.fake.use(double %d)
+  ret double %d
+}

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!

Copy link
Contributor

@tltao tltao left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants