Skip to content

Commit e19ce5d

Browse files
authored
Rollup merge of rust-lang#63431 - andjo403:revert_mir_simplification, r=matthewjasper
Revert "Simplify MIR generation for logical ops" This reverts commit e38e954. llvm were not able to optimize the code that well with the simplified mir. Closes: rust-lang#62993
2 parents ab2d7e9 + 676953f commit e19ce5d

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/librustc_mir/build/expr/into.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -79,59 +79,66 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7979
ExprKind::LogicalOp { op, lhs, rhs } => {
8080
// And:
8181
//
82-
// [block: If(lhs)] -true-> [else_block: dest = (rhs)]
83-
// | (false)
84-
// [shortcurcuit_block: dest = false]
82+
// [block: If(lhs)] -true-> [else_block: If(rhs)] -true-> [true_block]
83+
// | | (false)
84+
// +----------false-----------+------------------> [false_block]
8585
//
8686
// Or:
8787
//
88-
// [block: If(lhs)] -false-> [else_block: dest = (rhs)]
89-
// | (true)
90-
// [shortcurcuit_block: dest = true]
88+
// [block: If(lhs)] -false-> [else_block: If(rhs)] -true-> [true_block]
89+
// | (true) | (false)
90+
// [true_block] [false_block]
9191

92-
let (shortcircuit_block, mut else_block, join_block) = (
92+
let (true_block, false_block, mut else_block, join_block) = (
93+
this.cfg.start_new_block(),
9394
this.cfg.start_new_block(),
9495
this.cfg.start_new_block(),
9596
this.cfg.start_new_block(),
9697
);
9798

9899
let lhs = unpack!(block = this.as_local_operand(block, lhs));
99100
let blocks = match op {
100-
LogicalOp::And => (else_block, shortcircuit_block),
101-
LogicalOp::Or => (shortcircuit_block, else_block),
101+
LogicalOp::And => (else_block, false_block),
102+
LogicalOp::Or => (true_block, else_block),
102103
};
103104
let term = TerminatorKind::if_(this.hir.tcx(), lhs, blocks.0, blocks.1);
104105
this.cfg.terminate(block, source_info, term);
105106

107+
let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
108+
let term = TerminatorKind::if_(this.hir.tcx(), rhs, true_block, false_block);
109+
this.cfg.terminate(else_block, source_info, term);
110+
106111
this.cfg.push_assign_constant(
107-
shortcircuit_block,
112+
true_block,
108113
source_info,
109114
destination,
110115
Constant {
111116
span: expr_span,
112117
ty: this.hir.bool_ty(),
113118
user_ty: None,
114-
literal: match op {
115-
LogicalOp::And => this.hir.false_literal(),
116-
LogicalOp::Or => this.hir.true_literal(),
117-
},
119+
literal: this.hir.true_literal(),
118120
},
119121
);
120-
this.cfg.terminate(
121-
shortcircuit_block,
122+
123+
this.cfg.push_assign_constant(
124+
false_block,
122125
source_info,
123-
TerminatorKind::Goto { target: join_block },
126+
destination,
127+
Constant {
128+
span: expr_span,
129+
ty: this.hir.bool_ty(),
130+
user_ty: None,
131+
literal: this.hir.false_literal(),
132+
},
124133
);
125134

126-
let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
127-
this.cfg.push_assign(
128-
else_block,
135+
this.cfg.terminate(
136+
true_block,
129137
source_info,
130-
destination,
131-
Rvalue::Use(rhs),
138+
TerminatorKind::Goto { target: join_block },
132139
);
133140
this.cfg.terminate(
134-
else_block,
141+
false_block,
135142
source_info,
136143
TerminatorKind::Goto { target: join_block },
137144
);

0 commit comments

Comments
 (0)