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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>:

https://gcc.gnu.org/g:bfa70ddb650ec91c2511d351b2b3c3f78dfad6d4

commit r16-3470-gbfa70ddb650ec91c2511d351b2b3c3f78dfad6d4
Author: Andrew Pinski <andrew.pin...@oss.qualcomm.com>
Date:   Thu Aug 28 17:20:21 2025 -0700

    forwprop: Copy the memcmp optimization from strlen to forwprop [PR116651]

    To better optimize code dealing with `memcmp == 0` where we have
    a small constant size, we can inline the memcmp in those cases.
    There is code to do this in strlen but that is run too late in
    the case where we can figure out the value of one of the arguments
    to memcmp. So this copies the optimization to forwprop.

    An example of where this helps is:
    ```
    bool cmpvect(const std::vector<int> &a) { return a == std::vector<int>{10};
}
    ```

    Where the above should be optimized to just `return a.size() == 1 && a[0]
== 10;`.

    Note pr44130.c testcase needed to change as now it will be optimized away
otherwise.
    Note the loop in pr44130.c os also vectorized which it was not before.

    Note the optimization remains in strlen as the other part (memcmp ->
memcmp_eq)
    should move to either isel or fab and I didn't want to remove it just yet.

    Bootstrapped and tested on x86_64-linux-gnu.

    Changes since v1:
    * v2: Add verification of arguments to memcmp to simplify_builtin_memcmp.

            PR tree-optimization/116651
            PR tree-optimization/93265
            PR tree-optimization/103647
            PR tree-optimization/52171

    gcc/ChangeLog:

            * tree-ssa-forwprop.cc (simplify_builtin_memcmp): New function.
            (simplify_builtin_call): Call simplify_builtin_memcmp for memcmp
            memcmp_eq builtins.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr44130.c: Add an inline-asm clobber.
            * g++.dg/tree-ssa/vector-compare-1.C: New test.

    Signed-off-by: Andrew Pinski <andrew.pin...@oss.qualcomm.com>

Reply via email to