On 19 Jul 2015, at 12:13, Andrew Pinski <pins...@gmail.com> wrote: > On Thu, Jul 16, 2015 at 8:33 AM, Kyrill Tkachov <kyrylo.tkac...@arm.com> > wrote: >> Hi all, >> >> This patch improves codegen for expressions of the form: >> (x ? y + c1 : y + c2) when |c1 - c2| == 1 >> >> It matches the if_then_else of the two plus-immediates, >> performs one of them, then generates a conditional increment >> operation. >> >> Thus, for the code in the testcase we generate a single add, compare >> and cinc instruction rather than two adds, a compare and a csel. >> >> Bootstrapped and tested on aarch64. >> >> Ok for trunk? > > Why isn't this done in the generic code already. That is ifcvt? It > seems better to have it optimize it there rather than having a target > specific patch for something which is not really target specific > except maybe the cost.
I'd be better if something transformed x > 100 ? x - 2 : x - 1; into x - 1 - (x > 100) This is much easier to handle with combine patterns without having to rely on conditional move patterns. In this case, it seems that the if_then_else combine patterns will be formed by going through conditional move patterns. So if the target doesn't define conditional moves, it will never be able to get there. There are some other similar missed ifcvt cases, such as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54236#c9 Maybe the existing add<mode>cc handling in ifcvt could be extended to do that. Cheers, Oleg