[gcc r17-3025] match: Combine several patterns into fors.
Kael Andrew Franco via Gcc-cvs <[email protected]> Thu, 6 Aug 2026 10:27:33 +0000 (GMT)
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:aa356161379c0df6b47dabf69bff51b6a0b5cab7 commit r17-3025-gaa356161379c0df6b47dabf69bff51b6a0b5cab7 Author: Kael Andrew Alonzo Franco <[email protected]> Date: Thu Aug 6 06:26:42 2026 -0400 match: Combine several patterns into fors. This reduce genmatch's outputted C++ code. Bootstrapped and regtested on x86_64-pc-linux-gnu. gcc/ChangeLog: * match.pd: Combine several patterns into fors. Signed-off-by: Kael Andrew Franco <[email protected]> Diff: --- gcc/match.pd | 64 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 66cf628fc613..0bf2414b3f0c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1346,8 +1346,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (mult:c @0 (vec_cond (ne @0 integer_zerop) integer_zerop@2 @1)) @2) -/* Shifts by precision or greater result in zero. */ (for shift (lshift rshift) + /* Shifts by precision or greater result in zero. */ (simplify (shift @0 uniform_integer_cst_p@1) (if ((GIMPLE || !sanitize_flags_p (SANITIZE_SHIFT_EXPONENT)) @@ -1358,10 +1358,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Use a signed compare to leave negative shift counts alone. */ && wi::ges_p (wi::to_wide (uniform_integer_cst_p (@1)), element_precision (type))) - { build_zero_cst (type); }))) + { build_zero_cst (type); })) + /* Shifts by constants distribute over several binary operations: + (X (<<, >>) C) & (Y (<<, >>) C) -> (X & Y) (<<, >>) C. + (X (<<, >>) C) | (Y (<<, >>) C) -> (X | Y) (<<, >>) C. + (X (<<, >>) C) ^ (Y (<<, >>) C) -> (X ^ Y) (<<, >>) C. */ + (for op (bit_and bit_ior bit_xor) + (simplify + (op (shift:s @0 @1) (shift:s @2 @1)) + (if (INTEGRAL_TYPE_P (type)) + (shift (op @0 @2) @1))))) -/* Shifts by constants distribute over several binary operations, - hence (X << C) + (Y << C) can be simplified to (X + Y) << C. */ +/* (X << C) (+,-) (Y << C) -> (X (+,-) Y) << C. */ (for op (plus minus) (simplify (op (lshift:s @0 @1) (lshift:s @2 @1)) @@ -1370,16 +1378,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && !TYPE_SATURATING (type)) (lshift (op @0 @2) @1)))) -(for op (bit_and bit_ior bit_xor) - (simplify - (op (lshift:s @0 @1) (lshift:s @2 @1)) - (if (INTEGRAL_TYPE_P (type)) - (lshift (op @0 @2) @1))) - (simplify - (op (rshift:s @0 @1) (rshift:s @2 @1)) - (if (INTEGRAL_TYPE_P (type)) - (rshift (op @0 @2) @1)))) - /* (y << x) == x -> false and (y << x) != x -> true when y != 0. */ (for cmp (eq ne) (simplify @@ -1941,27 +1939,29 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_xor:c (bit_ior:c @0 @1) (bit_ior:c @0 (bit_not @1))) (bit_not @0)) -/* (x & y) | ~(x | y) -> ~(x ^ y) - (x ^ y) | ~(x | y) -> ~(x & y) */ -(for lop (bit_and bit_xor) - res (bit_xor bit_and) +(for op (bit_and bit_xor) + rop (bit_xor bit_and) + /* (x & y) | ~(x | y) -> ~(x ^ y) + (x ^ y) | ~(x | y) -> ~(x & y) */ + (simplify + (bit_ior:c (op:s @0 @1) (bit_not:s (bit_ior:s @0 @1))) + (bit_not (rop @0 @1))) + /* (x & y) ^ (x | y) -> x ^ y + (x ^ y) ^ (x | y) -> x & y */ + (simplify + (bit_xor:c (op @0 @1) (bit_ior @0 @1)) + (rop @0 @1)) + /* (x | y) - (x & y) -> x ^ y + (x | y) - (x ^ y) -> x & y */ (simplify - (bit_ior:c (lop:s @0 @1) (bit_not:s (bit_ior:s @0 @1))) - (bit_not (res @0 @1)))) + (minus (bit_ior @0 @1) (op @0 @1)) + (rop @0 @1))) /* (~x | y) ^ (x ^ y) -> x | ~y */ (simplify (bit_xor:c (bit_ior:cs (bit_not @0) @1) (bit_xor:s @0 @1)) (bit_ior @0 (bit_not @1))) -/* (x & y) ^ (x | y) -> x ^ y - (x ^ y) ^ (x | y) -> x & y */ -(for lop (bit_and bit_xor) - res (bit_xor bit_and) - (simplify - (bit_xor:c (lop @0 @1) (bit_ior @0 @1)) - (res @0 @1))) - /* (x & y) + (x ^ y) -> x | y */ /* (x & y) | (x ^ y) -> x | y */ /* (x & y) ^ (x ^ y) -> x | y */ @@ -1990,14 +1990,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (minus (bit_ior:cs @0 @1) @1) (bit_and @0 (bit_not @1))) -/* (x | y) - (x ^ y) -> x & y - (x | y) - (x & y) -> x ^ y */ -(for rop (bit_xor bit_and) - res (bit_and bit_xor) - (simplify - (minus (bit_ior @0 @1) (rop @0 @1)) - (res @0 @1))) - /* (x | y) & ~(x & y) -> x ^ y */ (simplify (bit_and:c (bit_ior @0 @1) (bit_not (bit_and @0 @1)))