[PATCH] D69257: Outline non returning functions unless a longjmp
Aditya Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 24 14:16:35 PDT 2019
hiraditya updated this revision to Diff 226325.
hiraditya added a comment.
Added testcase
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69257/new/
https://reviews.llvm.org/D69257
Files:
llvm/lib/Transforms/IPO/HotColdSplitting.cpp
llvm/test/Transforms/HotColdSplit/noreturn.ll
Index: llvm/test/Transforms/HotColdSplit/noreturn.ll
===================================================================
--- llvm/test/Transforms/HotColdSplit/noreturn.ll
+++ llvm/test/Transforms/HotColdSplit/noreturn.ll
@@ -59,6 +59,24 @@
ret void
}
+; Outline noreturn calls which are explicitly marked noreturn unless they are longjmp.
+
+; CHECK-LABEL: define {{.*}}@gap(
+; CHECK: gap.cold.1
+define void @gap(i32, %struct.__jmp_buf_tag*) {
+ %3 = icmp eq i32 %0, 0
+ tail call void @_Z10sideeffectv()
+ br i1 %3, label %5, label %4
+
+; <label>:4: ; preds = %2
+ tail call void @_assert_noreturn(%struct.__jmp_buf_tag* %1, i32 0)
+ unreachable
+
+; <label>:5: ; preds = %2
+ ret void
+}
+
+
; CHECK-LABEL: define {{.*}}@bar.cold.1(
; CHECK: call {{.*}}@llvm.trap(
@@ -69,3 +87,4 @@
declare void @_Z10sideeffectv()
declare void @longjmp(%struct.__jmp_buf_tag*, i32) noreturn nounwind
+declare void @_assert_noreturn(%struct.__jmp_buf_tag*, i32) noreturn nounwind
Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp
===================================================================
--- llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -117,8 +117,12 @@
if (blockEndsInUnreachable(BB)) {
if (auto *CI =
dyn_cast_or_null<CallInst>(BB.getTerminator()->getPrevNode()))
- if (CI->hasFnAttr(Attribute::NoReturn))
- return false;
+ if (CI->hasFnAttr(Attribute::NoReturn)) {
+ if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI))
+ return II->getIntrinsicID() != Intrinsic::longjmp;
+ CallSite CS(CI);
+ return !CS.getCalledFunction()->getName().startswith("longjmp");
+ }
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69257.226325.patch
Type: text/x-patch
Size: 1811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191024/9629c881/attachment.bin>
More information about the llvm-commits
mailing list