Skip to content

Commit 3cccdbd

Browse files
committed
Remove an unnecessary block/jump from the drop glue for @-pointer
The nested with_cond calls each introduce a "next" block, with the inner one just jumping to the outer one.
1 parent d405117 commit 3cccdbd

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/librustc/middle/trans/glue.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -546,18 +546,23 @@ pub fn decr_refcnt_maybe_free(bcx: block, box_ptr: ValueRef,
546546
let _icx = push_ctxt("decr_refcnt_maybe_free");
547547
let ccx = bcx.ccx();
548548

549-
do with_cond(bcx, IsNotNull(bcx, box_ptr)) |bcx| {
550-
let rc_ptr = GEPi(bcx, box_ptr, [0u, abi::box_field_refcnt]);
551-
let rc = Sub(bcx, Load(bcx, rc_ptr), C_int(ccx, 1));
552-
Store(bcx, rc, rc_ptr);
553-
let zero_test = ICmp(bcx, lib::llvm::IntEQ, C_int(ccx, 0), rc);
554-
do with_cond(bcx, zero_test) |bcx| {
555-
match box_ptr_ptr {
556-
Some(p) => free_ty(bcx, p, t),
557-
None => free_ty_immediate(bcx, box_ptr, t)
558-
}
559-
}
560-
}
549+
let decr_bcx = sub_block(bcx, "decr");
550+
let free_bcx = sub_block(decr_bcx, "free");
551+
let next_bcx = sub_block(bcx, "next");
552+
CondBr(bcx, IsNotNull(bcx, box_ptr), decr_bcx.llbb, next_bcx.llbb);
553+
554+
let rc_ptr = GEPi(decr_bcx, box_ptr, [0u, abi::box_field_refcnt]);
555+
let rc = Sub(decr_bcx, Load(decr_bcx, rc_ptr), C_int(ccx, 1));
556+
Store(decr_bcx, rc, rc_ptr);
557+
CondBr(decr_bcx, IsNull(decr_bcx, rc), free_bcx.llbb, next_bcx.llbb);
558+
559+
let free_bcx = match box_ptr_ptr {
560+
Some(p) => free_ty(free_bcx, p, t),
561+
None => free_ty_immediate(free_bcx, box_ptr, t)
562+
};
563+
Br(free_bcx, next_bcx.llbb);
564+
565+
next_bcx
561566
}
562567

563568

0 commit comments

Comments
 (0)