@@ -315,6 +315,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
315315 & mut self ,
316316 helper : TerminatorCodegenHelper < ' tcx > ,
317317 bx : & mut Bx ,
318+ bb : mir:: BasicBlock ,
318319 discr : & mir:: Operand < ' tcx > ,
319320 targets : & SwitchTargets ,
320321 ) {
@@ -328,10 +329,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
328329 let lltrue = helper. llbb_with_cleanup ( self , target) ;
329330 let llfalse = helper. llbb_with_cleanup ( self , targets. otherwise ( ) ) ;
330331 if switch_ty == bx. tcx ( ) . types . bool {
332+ let expect = if let Some ( x) = self . mir [ bb] . statements . last ( )
333+ && let mir:: StatementKind :: Intrinsic ( box mir:: NonDivergingIntrinsic :: Expect (
334+ op,
335+ kind,
336+ ) ) = & x. kind
337+ && self . codegen_operand ( bx, op) . immediate ( ) == discr. immediate ( )
338+ {
339+ match kind {
340+ mir:: ExpectKind :: True => ExpectKind :: True ,
341+ mir:: ExpectKind :: False => ExpectKind :: False ,
342+ mir:: ExpectKind :: Unpredictable => ExpectKind :: Unpredictable ,
343+ }
344+ } else {
345+ ExpectKind :: None
346+ } ;
347+
331348 // Don't generate trivial icmps when switching on bool.
332349 match test_value {
333- 0 => bx. cond_br ( discr. immediate ( ) , llfalse, lltrue) ,
334- 1 => bx. cond_br ( discr. immediate ( ) , lltrue, llfalse) ,
350+ 0 => bx. cond_br_with_expect ( discr. immediate ( ) , llfalse, lltrue, expect ) ,
351+ 1 => bx. cond_br_with_expect ( discr. immediate ( ) , lltrue, llfalse, expect . not ( ) ) ,
335352 _ => bug ! ( ) ,
336353 }
337354 } else {
@@ -1218,7 +1235,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12181235 }
12191236
12201237 mir:: TerminatorKind :: SwitchInt { ref discr, ref targets } => {
1221- self . codegen_switchint_terminator ( helper, bx, discr, targets) ;
1238+ self . codegen_switchint_terminator ( helper, bx, bb , discr, targets) ;
12221239 MergingSucc :: False
12231240 }
12241241
0 commit comments