On Thu, Jul 23, 2026 at 1:25 PM Jeffrey Law <[email protected]> wrote: > On 7/23/2026 1:52 PM, Andrea Pinski wrote: > > On Wed, Jul 22, 2026 at 6:14 AM <[email protected]> wrote: > >> From: Kyrylo Tkachov <[email protected]> > >> > >> The existing zero-one conditional rules fold A ? B : 0 to A & B. > >> They do not handle a negated Boolean arm, so these forms can retain a > >> diamond: > >> > >> A ? -B : 0 > >> A ? -B : -1 > >> > >> For GIMPLE condition A and zero-one B, fold them to: > >> > >> -(A & B) > >> -((A ^ 1) | B) > >> > >> Keep the rules in the GIMPLE-only group before the related zero-one > >> conditional folds. > >> On AArch64, the conditional branch > >> and fallback return in each direct form become a CMP, CCMP and CSETM > >> sequence. > >> > >> Bootstrapped and tested on aarch64-none-linux-gnu and x86_64-linux. > >> As discussed, this is a prerequisite transformation needed to avoid > >> regressions from: > >> https://gcc.gnu.org/pipermail/gcc-patches/2026-July/723788.html > > I was thinking about this some more. > > Can we do the following instead? > > Can we factor out the negative from the phi instead? > And I think there's a meaningful question about whether or not to > canonicalize to a conditional move or logical operations. In at least > two other threads we decided to canonicalize other cases towards > conditional moves. As we go from gimple to RTL we have the ability to > try different approaches to see what the target prefers.
I filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127654 for this issue. I also attached a patch to that bug which I will be submitting after writing up testcases and testing. This patch adds the factoring The heuristics are such that it only allows factoring in limited cases. The semi-limited case is if we had: ``` if (b) { ... t = (type) unsigned:1_var; // boolean is usually an unsigned:1 type arg = - t; } res = phi<arg, CST> ``` (I just noticed that I could introduce an undefined behavior for the negative case if the CST was the signed MIN; will fix that). Thanks, Andrea > > Jeff
