@@ -319,6 +319,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
319
319
targets : & SwitchTargets ,
320
320
) {
321
321
let discr = self . codegen_operand ( bx, discr) ;
322
+ // If our discr is a constant we can branch directly
323
+ if let Some ( const_discr) = bx. const_to_opt_u128 ( discr. immediate ( ) , true ) {
324
+ let target = targets. target_for_value ( const_discr) ;
325
+ bx. br ( helper. llbb_with_cleanup ( self , target) ) ;
326
+ return ;
327
+ } ;
328
+
322
329
let switch_ty = discr. layout . ty ;
323
330
let mut target_iter = targets. iter ( ) ;
324
331
if target_iter. len ( ) == 1 {
@@ -329,6 +336,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
329
336
let llfalse = helper. llbb_with_cleanup ( self , targets. otherwise ( ) ) ;
330
337
if switch_ty == bx. tcx ( ) . types . bool {
331
338
// Don't generate trivial icmps when switching on bool.
339
+ /*let discr = discr.immediate();
340
+ match (bx.const_to_opt_uint(discr), test_value) {
341
+ (Some(0), 0) => bx.br(lltrue),
342
+ (Some(1), 0) => bx.br(llfalse),
343
+ (Some(0), 1) => bx.br(llfalse),
344
+ (Some(1), 1) => bx.br(lltrue),
345
+ (None, 0) => bx.cond_br(discr, llfalse, lltrue),
346
+ (None, 1) => bx.cond_br(discr, lltrue, llfalse),
347
+ _ => bug!(),
348
+ }*/
332
349
match test_value {
333
350
0 => bx. cond_br ( discr. immediate ( ) , llfalse, lltrue) ,
334
351
1 => bx. cond_br ( discr. immediate ( ) , lltrue, llfalse) ,
0 commit comments