public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/105735] New: GCC failed to reduce &= loop_inv in loop.
@ 2022-05-26  7:54 crazylht at gmail dot com
  2022-05-26  8:29 ` [Bug tree-optimization/105735] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: crazylht at gmail dot com @ 2022-05-26  7:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105735
           Summary: GCC failed to reduce &= loop_inv in loop.
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---

This is another case from 47769, similar like 103462, but a little different.


unsigned long cfunc_one(unsigned long tmp, unsigned long bit2) {
    for (unsigned long bit = 0; bit < 64; bit++) {
        tmp &= bit2;
    }
    return tmp;
}


it should be equal to

unsigned long cfunc_one(unsigned long tmp, unsigned long bit2) {
   tmp &= bit2;
   return tmp;
}

but gcc generates a loop.

cfunc_one(unsigned long, unsigned long):
        mov     eax, 64
.L2:
        and     rdi, rsi
        dec     rax
        jne     .L2
        mov     rax, rdi
        ret

Similar for |= and ^=.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/105735] GCC failed to reduce &= loop_inv in loop.
  2022-05-26  7:54 [Bug tree-optimization/105735] New: GCC failed to reduce &= loop_inv in loop crazylht at gmail dot com
@ 2022-05-26  8:29 ` pinskia at gcc dot gnu.org
  2022-09-20  6:36 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-26  8:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually this is a dup of bug 101991.

*** This bug has been marked as a duplicate of bug 101991 ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/105735] GCC failed to reduce &= loop_inv in loop.
  2022-05-26  7:54 [Bug tree-optimization/105735] New: GCC failed to reduce &= loop_inv in loop crazylht at gmail dot com
  2022-05-26  8:29 ` [Bug tree-optimization/105735] " pinskia at gcc dot gnu.org
@ 2022-09-20  6:36 ` cvs-commit at gcc dot gnu.org
  2022-09-22  2:04 ` lingling.kong7 at gmail dot com
  2023-11-14  1:28 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-09-20  6:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Kong Lingling <konglin1@gcc.gnu.org>:

https://gcc.gnu.org/g:3a035f1932eeb26f997cf28a5c752617dd09cb91

commit r13-2729-g3a035f1932eeb26f997cf28a5c752617dd09cb91
Author: konglin1 <lingling.kong@intel.com>
Date:   Tue Sep 20 13:58:35 2022 +0800

    middle-end: handle bitop with an invariant induction.[PR105735]

    Enhance final_value_replacement_loop to handle bitop
    with an invariant induction.

    This patch will enable below optimization:

    {
    -  long unsigned int bit;
    -
    -  <bb 2> [local count: 32534376]:
    -
    -  <bb 3> [local count: 1041207449]:
    -  # tmp_10 = PHI <tmp_7(5), tmp_4(D)(2)>
    -  # bit_12 = PHI <bit_8(5), 0(2)>
    -  tmp_7 = bit2_6(D) & tmp_10;
    -  bit_8 = bit_12 + 1;
    -  if (bit_8 != 32)
    -    goto <bb 5>; [96.97%]
    -  else
    -    goto <bb 4>; [3.03%]
    -
    -  <bb 5> [local count: 1009658865]:
    -  goto <bb 3>; [100.00%]
    -
    -  <bb 4> [local count: 32534376]:
    -  # tmp_11 = PHI <tmp_7(3)>
    -  return tmp_11;
    +  tmp_11 = tmp_4 (D) & bit2_6 (D);
    +  return tmp_11;

    }

    gcc/ChangeLog:

            PR middle-end/105735
            * tree-scalar-evolution.cc
            (analyze_and_compute_bitop_with_inv_effect): New function.
            (final_value_replacement_loop): Enhanced to handle bitop
            with inv induction.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr105735-1.c: New test.
            * gcc.target/i386/pr105735-2.c: New test.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/105735] GCC failed to reduce &= loop_inv in loop.
  2022-05-26  7:54 [Bug tree-optimization/105735] New: GCC failed to reduce &= loop_inv in loop crazylht at gmail dot com
  2022-05-26  8:29 ` [Bug tree-optimization/105735] " pinskia at gcc dot gnu.org
  2022-09-20  6:36 ` cvs-commit at gcc dot gnu.org
@ 2022-09-22  2:04 ` lingling.kong7 at gmail dot com
  2023-11-14  1:28 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: lingling.kong7 at gmail dot com @ 2022-09-22  2:04 UTC (permalink / raw)
  To: gcc-bugs

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

kong lingling <lingling.kong7 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lingling.kong7 at gmail dot com

--- Comment #3 from kong lingling <lingling.kong7 at gmail dot com> ---
Fixed in gcc 13.0.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug tree-optimization/105735] GCC failed to reduce &= loop_inv in loop.
  2022-05-26  7:54 [Bug tree-optimization/105735] New: GCC failed to reduce &= loop_inv in loop crazylht at gmail dot com
                   ` (2 preceding siblings ...)
  2022-09-22  2:04 ` lingling.kong7 at gmail dot com
@ 2023-11-14  1:28 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-14  1:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

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

commit r14-5428-gfd1596f9962569afff6c9298a7c79686c6950bef
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Oct 30 15:43:48 2023 +0800

    Handle bitop with INTEGER_CST in analyze_and_compute_bitop_with_inv_effect.

    analyze_and_compute_bitop_with_inv_effect assumes the first operand is
    loop invariant which is not the case when it's INTEGER_CST.

    gcc/ChangeLog:

            PR tree-optimization/105735
            PR tree-optimization/111972
            * tree-scalar-evolution.cc
            (analyze_and_compute_bitop_with_inv_effect): Handle bitop with
            INTEGER_CST.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr105735-3.c: New test.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-14  1:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26  7:54 [Bug tree-optimization/105735] New: GCC failed to reduce &= loop_inv in loop crazylht at gmail dot com
2022-05-26  8:29 ` [Bug tree-optimization/105735] " pinskia at gcc dot gnu.org
2022-09-20  6:36 ` cvs-commit at gcc dot gnu.org
2022-09-22  2:04 ` lingling.kong7 at gmail dot com
2023-11-14  1:28 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).