On 11/8/22 13:15, Andrew Pinski via Gcc-patches wrote:
On Tue, Nov 8, 2022 at 12:02 PM Michael Collison <colli...@rivosinc.com> wrote:
This patches transforms (cond (and (x , 0x1) == 0), y, (z op y)) into
(-(and (x , 0x1)) & z ) op y, where op is a '^' or a '|'. It also
transforms (cond (and (x , 0x1) != 0), (z op y), y ) into (-(and (x ,
0x1)) & z ) op y.
Matching this patterns allows GCC to generate branchless code for one of
the functions in coremark.
Bootstrapped and tested on x86 and RISC-V. Okay?
This seems like a (much) reduced (simplified?) version of
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584411.html .
I have not had time for the last year to go through the comments on
that patch and resubmit it though.
It seems like you are aiming for one specific case in coremarks rather
than a more generic fix too.
I'm fairly confident it was developed independently. Michael did this
transformation for LLVM and reached out to me a month or two ago for
suggestions on the GCC implementation.
My recollection is I suggested phi-opt or match.pd with a slight
preference for phi-opt as I wasn't offhand sure if we'd have a form
suitable for match.pd.
THe pattern is just a conditional xor/ior with all is said and done.
While the inspiration comes from coremark, I don't think it's supposed
to be specific to coremark.
jeff