https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103514

            Bug ID: 103514
           Summary: Missing XOR-EQ-AND Optimization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: navidrahimi at microsoft dot com
  Target Milestone: ---

We are not optimizing &&-^-== combination, LLVM does it [1]:

// Proof of correctness https://alive2.llvm.org/ce/z/a4tuWF
bool
src (bool a, bool b)
{
    return (a && b) == (a ^ b);
}

bool
tgt (bool a, bool b)
{
    return !(a || b);
}


// Proof of correctness https://alive2.llvm.org/ce/z/w-iotd
bool
src (bool a, bool b)
{
     return (a && b) ^ (a == b);
}

bool
tgt (bool a, bool b)
{
    return !(a || b);
}


I will be sending a patch for this. This will solve it, I have to run the
testsuite and write a few tests:

/* (a && b) first_op (a second_op b) -> !(a || b) */
(for first_op (bit_xor eq)
 (for second_op (bit_xor eq)
 (simplify 
  (first_op:c (bit_and:c truth_valued_p@0 truth_valued_p@1) (second_op:c @0
@1))
   (if (first_op != second_op)
    (bit_not (bit_ior @0 @1))))))



1) https://compiler-explorer.com/z/WqTxYhG3s

Reply via email to