_Bool f2(_Bool a, _Bool b) { return !a ? !b : 0; } This can be optimized to `return !(a | b);`. This transformation is done by LLVM, but not by GCC.
_Bool f2(_Bool a, _Bool b) { return a ? !b : 1; } This similar pattern can be optimized to `return !(a & b);`. This transformation is done by LLVM, but not by GCC.
Note if we spell out the ?:, this would require PR 25290 too.
Mine, I have a patch which implements this. It needs https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571616.html first. I will be posting this once I write some testcases and do a bootstrap/test cycle.
Created attachment 50905 [details] Patch which is in testing (needs testcases) As I said for the case in this PR, it needs https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571616.html too. If you change !b to b; that is "!a ? b : 0", this patch will optimize it. The other patch is needed to allow to move !b out of the conditional.
(In reply to Andrew Pinski from comment #4) > Created attachment 50905 [details] > Patch which is in testing (needs testcases) > > As I said for the case in this PR, it needs > https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571616.html too. > > If you change !b to b; that is "!a ? b : 0", this patch will optimize it. > The other patch is needed to allow to move !b out of the conditional. This patch has one bug in it where we need a convert added. BUT then we run into a different missed optimization issue. _51 = p2_22 <= prephitmp_122; _44 = (logical(kind=4)) _51; _37 = p2_22 > prephitmp_122; _49 = (logical(kind=4)) _37; _38 = _49 & found_p_63; _46 = _38 | _44; This is really just: _51 = p2_22 <= prephitmp_122; _44 = (logical(kind=4)) _51; _46 = found_p_63| _44; That is we don't optimize: (a & ~b) | b into a | b if ~b has been converted already. The other thing I noticed is the cast should not be really needed but nothing removes it; I will look at that later. Note I could rewrite the pattern to do the simplification of the constants manually but I want to try to avoid that.
This depends on PR 100864 if I don't want to write out the 4 patterns.
Ok, this in the end is a dup of bug 89263. *** This bug has been marked as a duplicate of bug 89263 ***