Skip to content

Commit 5e810ea

Browse files
authored
Merge pull request #74451 from kubamracek/landingpads
[ARCOpts] Don't move releases before landingpads
2 parents fd6197f + f572000 commit 5e810ea

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/LLVMPasses/LLVMARCOpts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ static bool performLocalReleaseMotion(CallInst &Release, BasicBlock &BB,
274274
while (BBI != BB.begin()) {
275275
--BBI;
276276

277-
// Don't analyze PHI nodes. We can't move retains before them and they
278-
// aren't "interesting".
279-
if (isa<PHINode>(BBI) ||
277+
// Don't analyze PHI nodes and landingpad instructions. We can't move
278+
// releases before them and they aren't "interesting".
279+
if (isa<PHINode>(BBI) || isa<LandingPadInst>(BBI) ||
280280
// If we found the instruction that defines the value we're releasing,
281281
// don't push the release past it.
282282
&*BBI == Release.getArgOperand(0)) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: %swift-llvm-opt -passes=swift-llvm-arc-optimize %s | %FileCheck %s
2+
3+
target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
4+
target triple = "x86_64-apple-macosx10.9"
5+
6+
declare void @swift_release(ptr nocapture)
7+
declare void @swift_retain(ptr) nounwind
8+
declare ptr @_Znwm(i64)
9+
declare i32 @__gxx_personality_v0(...)
10+
11+
define ptr @foo(ptr %0) personality ptr @__gxx_personality_v0 {
12+
entry:
13+
%1 = tail call ptr @swift_retain(ptr %0)
14+
%2 = invoke ptr @_Znwm(i64 16)
15+
to label %continue unwind label %unwind
16+
continue:
17+
tail call void @swift_release(ptr %1)
18+
ret ptr %1
19+
unwind:
20+
%3 = landingpad { ptr, i32 }
21+
cleanup
22+
tail call void @swift_release(ptr %1)
23+
resume { ptr, i32 } %3
24+
}
25+
26+
; CHECK: unwind:
27+
; CHECK-NEXT: %3 = landingpad { ptr, i32 }
28+
; CHECK-NEXT: cleanup
29+
; CHECK-NEXT: tail call void @swift_release(ptr %1)

0 commit comments

Comments
 (0)