https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24574
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu.org --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Only for -Os, it's better to avoid the expensive division otherwise. Maybe if we can predict the division to be likely executed it is profitable to make it unconditional. Missing GIMPLE phiopt. absorbing_element_p needs to handle division for this. Index: gcc/tree-ssa-phiopt.c =================================================================== --- gcc/tree-ssa-phiopt.c (revision 238242) +++ gcc/tree-ssa-phiopt.c (working copy) @@ -812,7 +812,7 @@ neutral_element_p (tree_code code, tree /* Returns true if ARG is an absorbing element for operation CODE. */ static bool -absorbing_element_p (tree_code code, tree arg) +absorbing_element_p (tree_code code, tree arg, bool right) { switch (code) { @@ -823,6 +823,13 @@ absorbing_element_p (tree_code code, tre case BIT_AND_EXPR: return integer_zerop (arg); + case TRUNC_DIV_EXPR: + case CEIL_DIV_EXPR: + case FLOOR_DIV_EXPR: + case ROUND_DIV_EXPR: + case EXACT_DIV_EXPR: + return !right && integer_zerop (arg); + default: return false; } @@ -994,9 +1001,10 @@ value_replacement (basic_block cond_bb, && operand_equal_for_phi_arg_p (rhs1, cond_lhs) && neutral_element_p (code_def, cond_rhs, false)) || (operand_equal_for_phi_arg_p (arg1, cond_rhs) - && (operand_equal_for_phi_arg_p (rhs2, cond_lhs) - || operand_equal_for_phi_arg_p (rhs1, cond_lhs)) - && absorbing_element_p (code_def, cond_rhs)))) + && ((operand_equal_for_phi_arg_p (rhs2, cond_lhs) + && absorbing_element_p (code_def, cond_rhs, true)) + || (operand_equal_for_phi_arg_p (rhs1, cond_lhs) + && absorbing_element_p (code_def, cond_rhs, false)))))) { gsi = gsi_for_stmt (cond); if (INTEGRAL_TYPE_P (TREE_TYPE (lhs)))