Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit c8cc35e

Browse files
committed
Add comments to branch folding and reordering functions in simple_preopt.
1 parent 7fecdad commit c8cc35e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/codegen/src/simple_preopt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,11 @@ enum BranchOptKind {
555555
NotEqualZero,
556556
}
557557

558+
/// Fold comparisons into branch operations when possible.
559+
///
560+
/// This matches against operations which compare against zero, then use the
561+
/// result in a `brz` or `brnz` branch. It folds those two operations into a
562+
/// single `brz` or `brnz`.
558563
fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
559564
let info = match pos.func.dfg[inst] {
560565
InstructionData::Branch {
@@ -648,6 +653,11 @@ enum BranchOrderKind {
648653
InvertIcmpCond(IntCC, Value, Value),
649654
}
650655

656+
/// Reorder branches to encourage fallthroughs.
657+
///
658+
/// When an ebb ends with a conditional branch followed by an unconditional
659+
/// branch, this will reorder them if one of them is branching to the next Ebb
660+
/// layout-wise. The unconditional jump can then become a fallthrough.
651661
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst: Inst) {
652662
let info = match pos.func.dfg[inst] {
653663
InstructionData::Jump {

0 commit comments

Comments
 (0)