[llvm] caaacb8 - HotColdSplitting: Do not outline within noreturn functions

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 19 14:42:17 PST 2019


Author: Vedant Kumar
Date: 2019-12-19T14:06:24-08:00
New Revision: caaacb83995057b5226db97e5781b6f5f8d5c2b7

URL: https://github.com/llvm/llvm-project/commit/caaacb83995057b5226db97e5781b6f5f8d5c2b7
DIFF: https://github.com/llvm/llvm-project/commit/caaacb83995057b5226db97e5781b6f5f8d5c2b7.diff

LOG: HotColdSplitting: Do not outline within noreturn functions

A function marked `noreturn` may contain unreachable terminators: these
should not be considered cold, as the function may be a trampoline.

rdar://58068594

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/HotColdSplitting.cpp
    llvm/test/Transforms/HotColdSplit/noreturn.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
index 2bd3df3add7a..5e690714bfdf 100644
--- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -207,6 +207,11 @@ bool HotColdSplitting::shouldOutlineFrom(const Function &F) const {
   if (F.hasFnAttribute(Attribute::NoInline))
     return false;
 
+  // A function marked `noreturn` may contain unreachable terminators: these
+  // should not be considered cold, as the function may be a trampoline.
+  if (F.hasFnAttribute(Attribute::NoReturn))
+    return false;
+
   if (F.hasFnAttribute(Attribute::SanitizeAddress) ||
       F.hasFnAttribute(Attribute::SanitizeHWAddress) ||
       F.hasFnAttribute(Attribute::SanitizeThread) ||

diff  --git a/llvm/test/Transforms/HotColdSplit/noreturn.ll b/llvm/test/Transforms/HotColdSplit/noreturn.ll
index ca0f58815bf4..74f4cb18c7fb 100644
--- a/llvm/test/Transforms/HotColdSplit/noreturn.ll
+++ b/llvm/test/Transforms/HotColdSplit/noreturn.ll
@@ -23,6 +23,24 @@ define void @foo(i32, %struct.__jmp_buf_tag*) {
   ret void
 }
 
+; Don't outline within a noreturn function.
+
+; CHECK: define {{.*}}@xpc_objc_main(i32 {{.*}}) [[XPC_OBJC_MAIN_ATTRS:#[0-9]+]]
+; CHECK-NOT: xpc_objc_main.cold.1
+define void @xpc_objc_main(i32) noreturn {
+  %2 = icmp eq i32 %0, 0
+  tail call void @_Z10sideeffectv()
+  br i1 %2, label %4, label %3
+
+; <label>:3:                                      ; preds = %2
+  call void @_Z10sideeffectv()
+  unreachable
+
+; <label>:4:                                      ; preds = %2
+  ; Crash with an error message, "not supposed to return".
+  unreachable
+}
+
 ; Do outline noreturn calls marked cold.
 
 ; CHECK-LABEL: define {{.*}}@bar(
@@ -62,6 +80,8 @@ define void @baz(i32, %struct.__jmp_buf_tag*) {
 ; CHECK-LABEL: define {{.*}}@bar.cold.1(
 ; CHECK: call {{.*}}@llvm.trap(
 
+; CHECK: attributes [[XPC_OBJC_MAIN_ATTRS]] = { noreturn }
+
 declare void @sink() cold
 
 declare void @llvm.trap() noreturn cold


        


More information about the llvm-commits mailing list