> cost might also depend on the context in case flag setting > behavior differs for xor vs sub (on x86 sub looks strictly more > powerful here). The same is probably true when looking for > a combination with another bitwise operation. > > Btw, why not perform the optimization in expand_binop? That > for example already does > > if (binoptab == sub_optab && CONST_INT_P (op1)) > { > op1 = negate_rtx (mode, op1); > binoptab = add_optab; > } > > alternatively a targets expander can do the selection as well.
I was under the impression optabs/expand_binops is only supposed to "optimize" when it's clear that it is an optimization/canonicalization. I didn't see other functions there trying two alternatives and also none seems to use range information already. Regarding the proper costing (including the surroundings): is it even possible to encompass everything in such a localized decision? A target's expander decision would also not take this into account when deciding? If so, should we not perform this conversion generally and not only target specifc? Regards Robin