Skip to content

Commit dc44d41

Browse files
committed
remove noop landing pads in cleanup shims
These are already removed in the normal optimization pipeline - so this should slightly improve codegen performance, as these cleanup blocks are known to hurt LLVM. This un-regresses and is therefore a fix for #47442. However, the reporter of that issue should try using `-C panic=abort` instead of carefully avoiding panics.
1 parent e6072a7 commit dc44d41

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

src/librustc_mir/shim.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::fmt;
2828
use std::iter;
2929

3030
use transform::{add_moves_for_packed_drops, add_call_guards};
31-
use transform::{no_landing_pads, simplify};
31+
use transform::{remove_noop_landing_pads, no_landing_pads, simplify};
3232
use util::elaborate_drops::{self, DropElaborator, DropStyle, DropFlagMode};
3333
use util::patch::MirPatch;
3434

@@ -118,6 +118,7 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
118118
add_moves_for_packed_drops::add_moves_for_packed_drops(
119119
tcx, &mut result, instance.def_id());
120120
no_landing_pads::no_landing_pads(tcx, &mut result);
121+
remove_noop_landing_pads::remove_noop_landing_pads(tcx, &mut result);
121122
simplify::simplify_cfg(&mut result);
122123
add_call_guards::CriticalCallEdges.add_call_guards(&mut result);
123124
debug!("make_shim({:?}) = {:?}", instance, result);

src/librustc_mir/transform/remove_noop_landing_pads.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@ use util::patch::MirPatch;
2020
/// code for these.
2121
pub struct RemoveNoopLandingPads;
2222

23+
pub fn remove_noop_landing_pads<'a, 'tcx>(
24+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
25+
mir: &mut Mir<'tcx>)
26+
{
27+
if tcx.sess.no_landing_pads() {
28+
return
29+
}
30+
debug!("remove_noop_landing_pads({:?})", mir);
31+
32+
RemoveNoopLandingPads.remove_nop_landing_pads(mir)
33+
}
34+
2335
impl MirPass for RemoveNoopLandingPads {
2436
fn run_pass<'a, 'tcx>(&self,
2537
tcx: TyCtxt<'a, 'tcx, 'tcx>,
2638
_src: MirSource,
2739
mir: &mut Mir<'tcx>) {
28-
if tcx.sess.no_landing_pads() {
29-
return
30-
}
31-
32-
debug!("remove_noop_landing_pads({:?})", mir);
33-
self.remove_nop_landing_pads(mir);
40+
remove_noop_landing_pads(tcx, mir);
3441
}
3542
}
3643

src/test/codegen/issue-47442.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// check that we don't emit unneeded `resume` cleanup blocks for every
12+
// destructor.
13+
14+
// CHECK-NOT: Unwind
15+
16+
#![feature(test)]
17+
#![crate_type="rlib"]
18+
19+
extern crate test;
20+
21+
struct Foo {}
22+
23+
impl Drop for Foo {
24+
fn drop(&mut self) {
25+
test::black_box(());
26+
}
27+
}
28+
29+
#[no_mangle]
30+
pub fn foo() {
31+
let _foo = Foo {};
32+
}

0 commit comments

Comments
 (0)