Skip to content

Commit eac436b

Browse files
committed
What if we don't do this in debug?
1 parent e2a49e2 commit eac436b

File tree

1 file changed

+24
-24
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+24
-24
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -403,30 +403,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
403403
let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
404404
bx.cond_br_with_expect(cmp, lltarget, llotherwise, expect);
405405
}
406-
} else if target_iter.len() == 2
407-
&& self.mir[targets.otherwise()].is_empty_unreachable()
408-
&& targets.all_values().contains(&Pu128(0))
409-
&& targets.all_values().contains(&Pu128(1))
410-
{
411-
// This is the really common case for `bool`, `Option`, etc.
412-
// By using `trunc nuw` we communicate that other values are
413-
// impossible without needing `switch` or `assume`s.
414-
let true_bb = targets.target_for_value(1);
415-
let false_bb = targets.target_for_value(0);
416-
let true_ll = helper.llbb_with_cleanup(self, true_bb);
417-
let false_ll = helper.llbb_with_cleanup(self, false_bb);
418-
let true_cold = self.cold_blocks[true_bb];
419-
let false_cold = self.cold_blocks[false_bb];
420-
let expect = (true_cold != false_cold).then_some(!true_cold);
421-
422-
let bool_ty = bx.tcx().types.bool;
423-
let cond = if switch_ty == bool_ty {
424-
discr_value
425-
} else {
426-
let bool_llty = bx.immediate_backend_type(bx.layout_of(bool_ty));
427-
bx.unchecked_utrunc(discr_value, bool_llty)
428-
};
429-
bx.cond_br_with_expect(cond, true_ll, false_ll, expect);
430406
} else if self.cx.sess().opts.optimize == OptLevel::No
431407
&& target_iter.len() == 2
432408
&& self.mir[targets.otherwise()].is_empty_unreachable()
@@ -451,6 +427,30 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
451427
let llval = bx.const_uint_big(switch_llty, test_value1);
452428
let cmp = bx.icmp(IntPredicate::IntEQ, discr_value, llval);
453429
bx.cond_br(cmp, ll1, ll2);
430+
} else if target_iter.len() == 2
431+
&& self.mir[targets.otherwise()].is_empty_unreachable()
432+
&& targets.all_values().contains(&Pu128(0))
433+
&& targets.all_values().contains(&Pu128(1))
434+
{
435+
// This is the really common case for `bool`, `Option`, etc.
436+
// By using `trunc nuw` we communicate that other values are
437+
// impossible without needing `switch` or `assume`s.
438+
let true_bb = targets.target_for_value(1);
439+
let false_bb = targets.target_for_value(0);
440+
let true_ll = helper.llbb_with_cleanup(self, true_bb);
441+
let false_ll = helper.llbb_with_cleanup(self, false_bb);
442+
let true_cold = self.cold_blocks[true_bb];
443+
let false_cold = self.cold_blocks[false_bb];
444+
let expect = (true_cold != false_cold).then_some(!true_cold);
445+
446+
let bool_ty = bx.tcx().types.bool;
447+
let cond = if switch_ty == bool_ty {
448+
discr_value
449+
} else {
450+
let bool_llty = bx.immediate_backend_type(bx.layout_of(bool_ty));
451+
bx.unchecked_utrunc(discr_value, bool_llty)
452+
};
453+
bx.cond_br_with_expect(cond, true_ll, false_ll, expect);
454454
} else {
455455
let otherwise = targets.otherwise();
456456
let otherwise_cold = self.cold_blocks[otherwise];

0 commit comments

Comments
 (0)