[Bug tree-optimization/100173] telecom/viterb00data_1 has 16.92% regression compared O2 -ftree-vectorize -fvect-cost-model=very-cheap to O2 on CLX/ICX, 9% regression on znver3

"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]> Tue, 04 Aug 2026 17:06:35 +0000
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100173

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrea Pinski <[email protected]>:

https://gcc.gnu.org/g:1a751916c6d506ba49b318d38675184191647bf8

commit r17-2955-g1a751916c6d506ba49b318d38675184191647bf8
Author: Andrea Pinski <[email protected]>
Date:   Wed Jul 22 19:52:44 2026 -0700

    phiopt: Add some TARGET_MEM_REF support to factoring of loads [PR100173]

    The testcase in factor_op_phi-load-target_mem-1.c at -O2 gets:
    ```
      if (_4 > _6)
        goto <bb 4>; [50.00%]
      else
        goto <bb 5>; [50.00%]

      <bb 4> [local count: 531502204]:
      t_21 = MEM[(int *)c_19(D) + ivtmp.23_12 * 1];
      goto <bb 6>; [100.00%]

      <bb 5> [local count: 531502204]:
      t_20 = MEM[(int *)c_19(D) + 8B + ivtmp.23_12 * 1];

      <bb 6> [local count: 1063004408]:
      # t_13 = PHI <t_21(4), t_20(5)>
      # t1_14 = PHI <_4(4), _6(5)>
    ```

    But that MEM is a TARGET_MEM_REF which is not supported by
    factor_out_conditional_load yet. This adds simple TARGET_MEM_REF
    support by requiring the index/step and index2 to be all the same.
    It even supports a mismatched TARGET_MEM_REF with a MEM_REF but
    only if the TARGET_MEM_REF had an null index/step and index2.

    We now get a similar code generation for telecom/viterb00data_1 (EEMBC)
    at -O2 as LLVM.

    Changes since v1:
    * v2: Fix small issue checking of equality and nullptr of TARGET_MEM_REF
    operands.
    * v3: Fix operand_equal check.
    * v4: Add safe_operand_equal. Also use TMR_* instead of TREE_OPERAND.

    Bootstrapped and tested on x86_64-linux-gnu.

            PR tree-optimization/100173

    gcc/ChangeLog:

            * fold-const.h (safe_operand_equal_p): New function.
            * tree-ssa-phiopt.cc (factor_out_conditional_load): Add simple
            support for TARGET_MEM_REF.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/factor_op_phi-load-target_mem-1.c: New test.

    Signed-off-by: Andrea Pinski <[email protected]>