[llvm] r348404 - [CodeExtractor] Do not marked outlined calls which may resume EH as noreturn

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 5 11:35:37 PST 2018


Author: vedantk
Date: Wed Dec  5 11:35:37 2018
New Revision: 348404

URL: http://llvm.org/viewvc/llvm-project?rev=348404&view=rev
Log:
[CodeExtractor] Do not marked outlined calls which may resume EH as noreturn

Treat terminators which resume exception propagation as returning instructions
(at least, for the purposes of marking outlined functions `noreturn`). This is
to avoid inserting traps after calls to outlined functions which unwind.

rdar://46129950

Added:
    llvm/trunk/test/Transforms/HotColdSplit/unwind.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp

Modified: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp?rev=348404&r1=348403&r2=348404&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Wed Dec  5 11:35:37 2018
@@ -1369,9 +1369,12 @@ Function *CodeExtractor::extractCodeRegi
       DVI->eraseFromParent();
   }
 
-  // Mark the new function `noreturn` if applicable.
+  // Mark the new function `noreturn` if applicable. Terminators which resume
+  // exception propagation are treated as returning instructions. This is to
+  // avoid inserting traps after calls to outlined functions which unwind.
   bool doesNotReturn = none_of(*newFunction, [](const BasicBlock &BB) {
-    return isa<ReturnInst>(BB.getTerminator());
+    const Instruction *Term = BB.getTerminator();
+    return isa<ReturnInst>(Term) || isa<ResumeInst>(Term);
   });
   if (doesNotReturn)
     newFunction->setDoesNotReturn();

Added: llvm/trunk/test/Transforms/HotColdSplit/unwind.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/HotColdSplit/unwind.ll?rev=348404&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/HotColdSplit/unwind.ll (added)
+++ llvm/trunk/test/Transforms/HotColdSplit/unwind.ll Wed Dec  5 11:35:37 2018
@@ -0,0 +1,37 @@
+; RUN: opt -hotcoldsplit -S < %s | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.14.0"
+
+; Do not mark outlined functions which resume exception unwinding as noreturn.
+
+; CHECK-LABEL: define {{.*}}@foo.cold.1(
+; CHECK: resume
+; CHECK-NOT: noreturn
+define i32 @foo(i32 %cond) personality i8 0 {
+entry:
+  invoke void @llvm.donothing() to label %normal unwind label %exception
+
+exception:
+  %cleanup = landingpad i32 cleanup
+  br i1 undef, label %normal, label %continue_exception
+
+continue_exception:
+  call void @sideeffect(i32 0)
+  call void @sideeffect(i32 1)
+  call void @sink()
+  resume i32 undef
+
+normal:
+  br i1 undef, label %continue_exception, label %exit
+
+exit:
+  call void @sideeffect(i32 2)
+  ret i32 0
+}
+
+declare void @sideeffect(i32)
+
+declare void @sink() cold
+
+declare void @llvm.donothing() nounwind readnone




More information about the llvm-commits mailing list