public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114760] New: traling zero count detection failure
@ 2024-04-17 22:50 jiangning.liu at amperecomputing dot com
  2024-04-18  0:27 ` [Bug tree-optimization/114760] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jiangning.liu at amperecomputing dot com @ 2024-04-17 22:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114760
           Summary: traling zero count detection failure
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiangning.liu at amperecomputing dot com
  Target Milestone: ---

For this small case, gcc failed to detect trailing zero count calculation, so
the x86 instruction tzcnt cannot be generated, but clang can generate it.

unsigned  ntz32_6a(unsigned x) {
  int n;

  n = 32;
  while (x != 0) {
    n = n - 1;
    x = x + x;
  }
  return n;
}

If we slightly change "x = x + x" to "x = x << 1", the optimization will just
work.

unsigned  ntz32_6a(unsigned x) {
  int n;

  n = 32;
  while (x != 0) {
    n = n - 1;
    x = x << 1;
  }
  return n;
}

It seems number_of_iterations_cltz/number_of_iterations_cltz_complement in
tree-ssa-loop-niter.cc or somewhere else need to be enhanced.

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

* [Bug tree-optimization/114760] traling zero count detection failure
  2024-04-17 22:50 [Bug tree-optimization/114760] New: traling zero count detection failure jiangning.liu at amperecomputing dot com
@ 2024-04-18  0:27 ` pinskia at gcc dot gnu.org
  2024-04-18  6:50 ` rguenth at gcc dot gnu.org
  2024-05-11 10:00 ` [Bug tree-optimization/114760] trailing " cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-18  0:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/114760] traling zero count detection failure
  2024-04-17 22:50 [Bug tree-optimization/114760] New: traling zero count detection failure jiangning.liu at amperecomputing dot com
  2024-04-18  0:27 ` [Bug tree-optimization/114760] " pinskia at gcc dot gnu.org
@ 2024-04-18  6:50 ` rguenth at gcc dot gnu.org
  2024-05-11 10:00 ` [Bug tree-optimization/114760] trailing " cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-18  6:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think it's also a missed canonicalization for x << 1 vs. x + x (and 2*x).

unsigned a, b, c;
void foo (unsigned x)
{
  a = x << 1;
  b = x + x;
  c = 2 * x;
}

x + x gets folded to 2 * x before gimplification.  value-numbering figures
x << 1 is the same as 2 * x but we don't canonicalize it so pattern matching
needs to match both variants.

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

* [Bug tree-optimization/114760] trailing zero count detection failure
  2024-04-17 22:50 [Bug tree-optimization/114760] New: traling zero count detection failure jiangning.liu at amperecomputing dot com
  2024-04-18  0:27 ` [Bug tree-optimization/114760] " pinskia at gcc dot gnu.org
  2024-04-18  6:50 ` rguenth at gcc dot gnu.org
@ 2024-05-11 10:00 ` cvs-commit at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-11 10:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Di Zhao <dzhao@gcc.gnu.org>:

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

commit r15-380-g1b0919cd147a2b6ccdee2b1217bf0200bdcc87aa
Author: dzhao.ampere <di.zhao@amperecomputing.com>
Date:   Fri May 10 11:55:18 2024 +0800

    tree-optimization/114760 - check variants of >> and << in loop-niter

    When recognizing bit counting idiom, include pattern "x * 2"
    for "x << 1", and "x / 2" for "x >> 1" (given x is unsigned).

    gcc/ChangeLog:
            PR tree-optimization/114760
            * tree-ssa-loop-niter.cc (is_lshift_by_1): New function
            to check if STMT is equivalent to x << 1.
            (is_rshift_by_1): New function to check if STMT is
            equivalent to x >> 1.
            (number_of_iterations_cltz): Enhance the identification
            of logical shift by one.
            (number_of_iterations_cltz_complement): Enhance the
            identification of logical shift by one.

    gcc/testsuite/ChangeLog:
            PR tree-optimization/114760
            * gcc.dg/tree-ssa/pr114760-1.c: New test.
            * gcc.dg/tree-ssa/pr114760-2.c: New test.

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

end of thread, other threads:[~2024-05-11 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 22:50 [Bug tree-optimization/114760] New: traling zero count detection failure jiangning.liu at amperecomputing dot com
2024-04-18  0:27 ` [Bug tree-optimization/114760] " pinskia at gcc dot gnu.org
2024-04-18  6:50 ` rguenth at gcc dot gnu.org
2024-05-11 10:00 ` [Bug tree-optimization/114760] trailing " 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).