https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112935
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|needs-bisection |missed-optimization Target|loongarch64-*-* |loongson Component|tree-optimization |target --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Either r14-1655-g52c92fb3f40050 or r14-1654-g7ceed7e3e29c33 causes the difference in the gimple level. BUT `a * boolean` is Canonical form and expr.cc expands it as `a & -boolean`: ``` /* Expand X*Y as X&-Y when Y must be zero or one. */ ... bool speed = optimize_insn_for_speed_p (); int cost = add_cost (speed, mode) + neg_cost (speed, mode); struct algorithm algorithm; enum mult_variant variant; if (CONST_INT_P (op1) ? !choose_mult_variant (mode, INTVAL (op1), &algorithm, &variant, cost) : cost < mul_cost (speed, mode)) { target = bit0_p ? expand_and (mode, negate_rtx (mode, op0), op1, target) : expand_and (mode, op0, negate_rtx (mode, op1), target); return REDUCE_BIT_FIELD (target); } ``` Which means the cost model for loongson is wrong here. Though it is comparing the cost of doing + and - to a * here though it should be & and - but most target's + and & have a similar cost.