https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112533
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:1c9808a71207eb217f4e190c60f2755a796b90d4 commit r17-632-g1c9808a71207eb217f4e190c60f2755a796b90d4 Author: Shivam Gupta <[email protected]> Date: Wed May 20 09:16:32 2026 +0530 match.pd: Simplify (T)(x) == (T)(y) -> (T)(x ^ y) == 0 [PR112533] This is a follow-up to the -O1 patch for PR112533. At -O2, GCC lowers (~x & 1) == (~y & 1) via inlining into: _14 = ~x; _12 = (bool) _14; _13 = ~y; _9 = (bool) _13; _8 = _9 == _12; The NOT cancellation (~x == ~y -> x == y) is handled by existing forwprop rules before this rule fires. Add match.pd rule for eq and ne: (T)(x) == (T)(y) -> (T)(x ^ y) == 0 (T)(x) != (T)(y) -> (T)(x ^ y) != 0 Bootstrapped and regression tested on aarch64-linux-gnu with RUNTESTFLAGS="tree-ssa.exp". Changes since v1: * v5: Split testcase into bool, integral, short and float-specific files. * v4: Moved match rule to right place alongside other simple_comparison narrowing cases. * v3: Simplify match rule. Add more cases in test file. * v2: Generalize the match rule to generic narrowing integral equality comparisons from bool equality. PR tree-optimization/112533 gcc/ChangeLog: * match.pd: Add integral narrowing eq/ne to XOR-against-zero rule for (T)(x) == (T)(y) where precision(T) < precision(x). gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/narrow-bool-eq.c: New test. * gcc.dg/tree-ssa/narrow-integral-eq.c: New test. * gcc.dg/tree-ssa/narrow-short-eq.c: New test. * gcc.dg/tree-ssa/narrow-float-eq.c: New test. Signed-off-by: Shivam Gupta <[email protected]>
