-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Skip tranformConstExprCastCall for naked function #76496
Conversation
@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
ping |
@@ -0,0 +1,16 @@ | |||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | |||
|
|||
define dso_local void @naked_func() #0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove dso_local.
Also directly use naked
here instead of an attribute group.
define i32 @main() { | ||
; CHECK: call void @naked_func(i32 noundef 1) | ||
entry: | ||
call void @naked_func(i32 noundef 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove noundef.
@@ -0,0 +1,16 @@ | |||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -199,17 +199,17 @@ attributes #8 = { noreturn nounwind } | |||
; CHECK-LABEL: define weak_odr hidden void @__cfi_check_fail | |||
; CHECK-SAME: (ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]]) #[[ATTR2:[0-9]+]] { | |||
; CHECK-NEXT: entry: | |||
; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq ptr [[TMP0]], null, !nosanitize !13 | |||
; CHECK-NEXT: br i1 [[DOTNOT]], label [[TRAP:%.*]], label [[CONT:%.*]], !nosanitize !13 | |||
; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq ptr [[TMP0]], null, !nosanitize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rerun update_test_checks.py instead of manually editing the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thx advice for test cases :) |
Fix this issue #72843 .
For naked function, assembly might be using an argument, or otherwise rely on the frame layout, so don't transformConstExprCastCall