From 05ff53a6f5be76da5c94368b958832fc8a90755f Mon Sep 17 00:00:00 2001 From: Eric Henry Date: Mon, 15 Mar 2021 23:27:43 -0400 Subject: [PATCH] Make the then branch the one that will happen most often --- compiler/gen/src/llvm/build.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index 3ff74e4106..ba3a4de6e6 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -4781,24 +4781,25 @@ fn build_int_binop<'a, 'ctx, 'env>( NumIsMultipleOf => { /* this builds the following construct - if rhs == 0 { - lhs == 0 - } else { + if rhs != 0 { let rem = lhs % rhs; rem == 0 + } else { + // rhs == 0 && lhs ==0 + lhs == 0 } */ let zero = rhs.get_type().const_zero(); - let condition_rhs = bd.build_int_compare(IntPredicate::EQ, rhs, zero, "is_zero_rhs"); + let condition_rhs = bd.build_int_compare(IntPredicate::NE, rhs, zero, "is_zero_rhs"); let condition_lhs = bd.build_int_compare(IntPredicate::EQ, lhs, zero, "is_zero_lhs"); let current_block = bd.get_insert_block().unwrap(); //block that we are in right now; - let else_block = env.context.append_basic_block(parent, "else"); // - let cont_block = env.context.append_basic_block(parent, "branchcont"); + let then_block = env.context.append_basic_block(parent, "then"); + let cont_block = env.context.append_basic_block(parent, "branchcont"); // - bd.build_conditional_branch(condition_rhs, cont_block, else_block); + bd.build_conditional_branch(condition_rhs, then_block, cont_block); - bd.position_at_end(else_block); + bd.position_at_end(then_block); let rem = bd.build_int_signed_rem(lhs, rhs, "int_rem"); let condition_rem = bd.build_int_compare(IntPredicate::EQ, rem, zero, "is_zero_rem"); @@ -4810,8 +4811,8 @@ fn build_int_binop<'a, 'ctx, 'env>( let phi = bd.build_phi(env.context.bool_type(), "branch"); phi.add_incoming(&[ + (&condition_rem, then_block), (&condition_lhs, current_block), - (&condition_rem, else_block), ]); phi.as_basic_value()