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.
Jeff