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

--- Comment #24 from Kishan Parmar <kishan at gcc dot gnu.org> ---
I’ve tested below patch, and can see xxsel being generated correctly.
diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
index c4de035b44f..4d87ce8d131 100644
--- a/gcc/simplify-rtx.cc
+++ b/gcc/simplify-rtx.cc
@@ -3997,7 +3997,7 @@ simplify_context::simplify_binary_operation_1 (rtx_code
code,
         machines, and also has shorter instruction path length.  */
       if (GET_CODE (op0) == AND
          && GET_CODE (XEXP (op0, 0)) == XOR
-         && CONST_INT_P (XEXP (op0, 1))
+         && (CONST_INT_P (XEXP (op0, 1)) || REG_P (XEXP (op0, 1)))
          && rtx_equal_p (XEXP (XEXP (op0, 0), 0), trueop1))
        {
          rtx a = trueop1;
@@ -4011,7 +4011,7 @@ simplify_context::simplify_binary_operation_1 (rtx_code
code,
       /* Similarly, (xor (and (xor A B) C) B) as (ior (and A C) (and B ~C)) 
*/
       else if (GET_CODE (op0) == AND
          && GET_CODE (XEXP (op0, 0)) == XOR
-         && CONST_INT_P (XEXP (op0, 1))
+         && (CONST_INT_P (XEXP (op0, 1)) || REG_P (XEXP (op0, 1)))
          && rtx_equal_p (XEXP (XEXP (op0, 0), 1), trueop1))
        {
          rtx a = XEXP (XEXP (op0, 0), 0);

However, I tested the patch on i386 and saw two test failures.
That’s because on i386 and AArch64, I see existing .md patterns still written
as
(xor (and (xor A B) C) B) instead of the canonicalized (ior (and A C) (and B
~C)).
Should we consider updating those patterns to match the new form, or is there a
specific reason why the current (xor (and (xor A B) C) B) form is preferred for
those targets?

Reply via email to