Skip tranformConstExprCastCall for naked function#76496
Merged
Conversation
Member
|
@llvm/pr-subscribers-llvm-transforms Author: None (hstk30-hw) ChangesFix this issue #72843 . For naked function, assembly might be using an argument, or otherwise rely on the frame layout, so don't transformConstExprCastCall Full diff: https://github.com/llvm/llvm-project/pull/76496.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 3b7fe7fa226607..43d4496571be50 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3850,6 +3850,12 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
if (Callee->hasFnAttribute("thunk"))
return false;
+ // If this is a call to a naked function, the assembly might be
+ // using an argument, or otherwise rely on the frame layout,
+ // the function prototype will mismatch.
+ if (Callee->hasFnAttribute(Attribute::Naked))
+ return false;
+
// If this is a musttail call, the callee's prototype must match the caller's
// prototype with the exception of pointee types. The code below doesn't
// implement that, so we can't do this transform.
diff --git a/llvm/test/Transforms/InstCombine/cast-call-naked.ll b/llvm/test/Transforms/InstCombine/cast-call-naked.ll
new file mode 100644
index 00000000000000..a0b0d48b44d4eb
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/cast-call-naked.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define dso_local void @naked_func() #0 {
+entry:
+ tail call void asm sideeffect "mov r1, r0", ""()
+ unreachable
+}
+
+define i32 @main() {
+; CHECK: call void @naked_func(i32 noundef 1)
+entry:
+ call void @naked_func(i32 noundef 1)
+ ret i32 0
+}
+
+attributes #0 = { naked }
|
d07d219 to
d4a394d
Compare
Contributor
Author
|
ping |
nikic
reviewed
Jan 1, 2024
Contributor
There was a problem hiding this comment.
Remove dso_local.
Also directly use naked here instead of an attribute group.
Contributor
There was a problem hiding this comment.
Use update_test_checks.py.
Preferably also find where all other tests for this transform are and add it to that file, instead of creating a new one.
Contributor
There was a problem hiding this comment.
Rerun update_test_checks.py instead of manually editing the file.
Contributor
Author
|
Thx advice for test cases :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix this issue #72843 .
For naked function, assembly might be using an argument, or otherwise rely on the frame layout, so don't transformConstExprCastCall