Skip to content

Commit 64c6978

Browse files
author
Ariel Ben-Yehuda
committed
remove cleanup branches to the resume block
This improves LLVM performance by 10% lost during the shimmir transition.
1 parent 452bf08 commit 64c6978

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/librustc_mir/transform/simplify.rs

+34
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
124124
self.collapse_goto_chain(successor, &mut changed);
125125
}
126126

127+
changed |= self.simplify_unwind(&mut terminator);
128+
127129
let mut new_stmts = vec![];
128130
let mut inner_changed = true;
129131
while inner_changed {
@@ -238,6 +240,38 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
238240
true
239241
}
240242

243+
// turn an unwind branch to a resume block into a None
244+
fn simplify_unwind(&mut self, terminator: &mut Terminator<'tcx>) -> bool {
245+
let unwind = match terminator.kind {
246+
TerminatorKind::Drop { ref mut unwind, .. } |
247+
TerminatorKind::DropAndReplace { ref mut unwind, .. } |
248+
TerminatorKind::Call { cleanup: ref mut unwind, .. } |
249+
TerminatorKind::Assert { cleanup: ref mut unwind, .. } =>
250+
unwind,
251+
_ => return false
252+
};
253+
254+
if let &mut Some(unwind_block) = unwind {
255+
let is_resume_block = match self.basic_blocks[unwind_block] {
256+
BasicBlockData {
257+
ref statements,
258+
terminator: Some(Terminator {
259+
kind: TerminatorKind::Resume, ..
260+
}), ..
261+
} if statements.is_empty() => true,
262+
_ => false
263+
};
264+
if is_resume_block {
265+
debug!("simplifying unwind to {:?} from {:?}",
266+
unwind_block, terminator.source_info);
267+
*unwind = None;
268+
}
269+
return is_resume_block;
270+
}
271+
272+
false
273+
}
274+
241275
fn strip_nops(&mut self) {
242276
for blk in self.basic_blocks.iter_mut() {
243277
blk.statements.retain(|stmt| if let StatementKind::Nop = stmt.kind {

src/test/codegen/drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn droppy() {
3636
// CHECK-NOT: call{{.*}}drop{{.*}}SomeUniqueName
3737
// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
3838
// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
39-
// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
39+
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
4040
// CHECK-NOT: {{(call|invoke).*}}drop{{.*}}SomeUniqueName
4141
// The next line checks for the } that ends the function definition
4242
// CHECK-LABEL: {{^[}]}}

src/test/codegen/personality_lifetimes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ pub fn test() {
3737
// CHECK: bitcast{{.*}}personalityslot
3838
// CHECK-NEXT: call void @llvm.lifetime.start
3939
might_unwind();
40+
let _t = S;
4041
might_unwind();
4142
}

0 commit comments

Comments
 (0)