@@ -3620,15 +3620,6 @@ fn build_leaf_fn<M: Module>(
36203620 // param instead of baking. 0 = plain function / AOT.
36213621 dynamic_prefix : usize ,
36223622) -> Result < cranelift_module:: FuncId , CompileError > {
3623- // Predicate fusion improves arithmetic loops, but measured call-containing
3624- // bodies can regress under the altered branch form. Keep their established
3625- // lowering until that tradeoff is resolved independently.
3626- let fuse_integer_predicates = !ops. iter ( ) . any ( |op| {
3627- matches ! (
3628- op,
3629- Op :: Call ( _) | Op :: Apply ( _) | Op :: CallBuiltin ( ..) | Op :: CallBuiltinSym ( ..)
3630- )
3631- } ) ;
36323623 lowering:: imm_pool_reset ( ) ;
36333624 LAST_IR_STATS . with ( |c| c. set ( ( 0 , 0 , 0 , 0 ) ) ) ;
36343625 let frontend_config = module. target_config ( ) ;
@@ -4067,29 +4058,21 @@ fn build_leaf_fn<M: Module>(
40674058 Op :: GotoIfNil ( t) | Op :: GotoIfNotNil ( t) => {
40684059 let cond = stack. pop ( ) . ok_or ( CompileError :: StackUnderflow ) ?;
40694060 write_stack_to_vars ( & mut fb, & vars, & stack) ;
4061+ let is_nil =
4062+ fb. ins ( )
4063+ . icmp_imm_u ( IntCC :: Equal , cond, Value :: NIL . bits ( ) as i64 ) ;
40704064 let tu = * t as usize ;
40714065 let mut target = block_for[ & tu] ;
40724066 let fallthrough = block_for[ & ( i + 1 ) ] ;
40734067 let backedge = ( tu <= i) . then ( || fb. create_block ( ) ) ;
40744068 if let Some ( tramp) = backedge {
40754069 target = tramp;
40764070 }
4071+ // brif takes the `then` block when the condition is true.
40774072 if matches ! ( op, Op :: GotoIfNil ( _) ) {
4078- emit_nil_branch (
4079- & mut fb,
4080- cond,
4081- fuse_integer_predicates,
4082- target,
4083- fallthrough,
4084- ) ;
4073+ fb. ins ( ) . brif ( is_nil, target, & [ ] , fallthrough, & [ ] ) ;
40854074 } else {
4086- emit_nil_branch (
4087- & mut fb,
4088- cond,
4089- fuse_integer_predicates,
4090- fallthrough,
4091- target,
4092- ) ;
4075+ fb. ins ( ) . brif ( is_nil, fallthrough, & [ ] , target, & [ ] ) ;
40934076 }
40944077 if let Some ( tramp) = backedge {
40954078 // Taken-edge trampoline carrying the back-edge poll.
@@ -4121,6 +4104,9 @@ fn build_leaf_fn<M: Module>(
41214104 // top slot — implementing the "ElsePop".
41224105 let cond = * stack. last ( ) . ok_or ( CompileError :: StackUnderflow ) ?;
41234106 write_stack_to_vars ( & mut fb, & vars, & stack) ;
4107+ let is_nil =
4108+ fb. ins ( )
4109+ . icmp_imm_u ( IntCC :: Equal , cond, Value :: NIL . bits ( ) as i64 ) ;
41244110 let tu = * t as usize ;
41254111 let mut target = block_for[ & tu] ;
41264112 let fallthrough = block_for[ & ( i + 1 ) ] ;
@@ -4129,21 +4115,9 @@ fn build_leaf_fn<M: Module>(
41294115 target = tramp;
41304116 }
41314117 if matches ! ( op, Op :: GotoIfNilElsePop ( _) ) {
4132- emit_nil_branch (
4133- & mut fb,
4134- cond,
4135- fuse_integer_predicates,
4136- target,
4137- fallthrough,
4138- ) ;
4118+ fb. ins ( ) . brif ( is_nil, target, & [ ] , fallthrough, & [ ] ) ;
41394119 } else {
4140- emit_nil_branch (
4141- & mut fb,
4142- cond,
4143- fuse_integer_predicates,
4144- fallthrough,
4145- target,
4146- ) ;
4120+ fb. ins ( ) . brif ( is_nil, fallthrough, & [ ] , target, & [ ] ) ;
41474121 }
41484122 if let Some ( tramp) = backedge {
41494123 fb. switch_to_block ( tramp) ;
0 commit comments