about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@users.noreply.github.com>2019-08-10 10:52:04 +0200
committerAndreas Jonson <andjo403@users.noreply.github.com>2019-08-10 10:52:04 +0200
commit676953fde9120cda62e4ef2f75a804af7481d6af (patch)
tree8c98600d6e5946a47cf773447eca87fb79092994
parentbe8bbb06976c8065425b18e9cbe24a6d1d4e7515 (diff)
downloadrust-676953fde9120cda62e4ef2f75a804af7481d6af.tar.gz
rust-676953fde9120cda62e4ef2f75a804af7481d6af.zip
Revert "Simplify MIR generation for logical ops"
This reverts commit e38e954a0d249f88d0a55504f70d6055e865a931.

llvm were not able to optimize the code that well with the simplified mir.

Closes: #62993
-rw-r--r--src/librustc_mir/build/expr/into.rs53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs
index 2815361a647..02ab53fe8c1 100644
--- a/src/librustc_mir/build/expr/into.rs
+++ b/src/librustc_mir/build/expr/into.rs
@@ -79,17 +79,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             ExprKind::LogicalOp { op, lhs, rhs } => {
                 // And:
                 //
-                // [block: If(lhs)] -true-> [else_block: dest = (rhs)]
-                //        | (false)
-                //  [shortcurcuit_block: dest = false]
+                // [block: If(lhs)] -true-> [else_block: If(rhs)] -true-> [true_block]
+                //        |                          | (false)
+                //        +----------false-----------+------------------> [false_block]
                 //
                 // Or:
                 //
-                // [block: If(lhs)] -false-> [else_block: dest = (rhs)]
-                //        | (true)
-                //  [shortcurcuit_block: dest = true]
+                // [block: If(lhs)] -false-> [else_block: If(rhs)] -true-> [true_block]
+                //        | (true)                   | (false)
+                //  [true_block]               [false_block]
 
-                let (shortcircuit_block, mut else_block, join_block) = (
+                let (true_block, false_block, mut else_block, join_block) = (
+                    this.cfg.start_new_block(),
                     this.cfg.start_new_block(),
                     this.cfg.start_new_block(),
                     this.cfg.start_new_block(),
@@ -97,41 +98,47 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
 
                 let lhs = unpack!(block = this.as_local_operand(block, lhs));
                 let blocks = match op {
-                    LogicalOp::And => (else_block, shortcircuit_block),
-                    LogicalOp::Or => (shortcircuit_block, else_block),
+                    LogicalOp::And => (else_block, false_block),
+                    LogicalOp::Or => (true_block, else_block),
                 };
                 let term = TerminatorKind::if_(this.hir.tcx(), lhs, blocks.0, blocks.1);
                 this.cfg.terminate(block, source_info, term);
 
+                let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
+                let term = TerminatorKind::if_(this.hir.tcx(), rhs, true_block, false_block);
+                this.cfg.terminate(else_block, source_info, term);
+
                 this.cfg.push_assign_constant(
-                    shortcircuit_block,
+                    true_block,
                     source_info,
                     destination,
                     Constant {
                         span: expr_span,
                         ty: this.hir.bool_ty(),
                         user_ty: None,
-                        literal: match op {
-                            LogicalOp::And => this.hir.false_literal(),
-                            LogicalOp::Or => this.hir.true_literal(),
-                        },
+                        literal: this.hir.true_literal(),
                     },
                 );
-                this.cfg.terminate(
-                    shortcircuit_block,
+
+                this.cfg.push_assign_constant(
+                    false_block,
                     source_info,
-                    TerminatorKind::Goto { target: join_block },
+                    destination,
+                    Constant {
+                        span: expr_span,
+                        ty: this.hir.bool_ty(),
+                        user_ty: None,
+                        literal: this.hir.false_literal(),
+                    },
                 );
 
-                let rhs = unpack!(else_block = this.as_local_operand(else_block, rhs));
-                this.cfg.push_assign(
-                    else_block,
+                this.cfg.terminate(
+                    true_block,
                     source_info,
-                    destination,
-                    Rvalue::Use(rhs),
+                    TerminatorKind::Goto { target: join_block },
                 );
                 this.cfg.terminate(
-                    else_block,
+                    false_block,
                     source_info,
                     TerminatorKind::Goto { target: join_block },
                 );