public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
@ 2024-03-02  4:19 141242068 at smail dot nju.edu.cn
  2024-03-02  4:40 ` [Bug tree-optimization/114203] [13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: 141242068 at smail dot nju.edu.cn @ 2024-03-02  4:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114203
           Summary: Miscompilation: A possible miscompilation in GCC 13
                    and 14 with option -Os
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 141242068 at smail dot nju.edu.cn
  Target Milestone: ---

The reproduce link: https://gcc.godbolt.org/z/T48jbo5e7

The reproducer (diff: `gcc-14 -O0` and `gcc-14 -Os`):
```
int foo (unsigned char b) {
    int c = 0;

    while (b) {
        b >>= 1;
        c++;
    }

    return c;
}

int main()
{
  if (foo(0) != 0)
    __builtin_abort ();
  return 0;
}
```

I have sanitized this program using ubsan and asan, ubsan and asans outputs
nothing, so I think this is likely a miscompilation bug.

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

* [Bug tree-optimization/114203] [13/14 Regression] Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
  2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
@ 2024-03-02  4:40 ` pinskia at gcc dot gnu.org
  2024-03-04  9:36 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-02  4:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |tree-optimization
   Last reconfirmed|                            |2024-03-02
                 CC|                            |pinskia at gcc dot gnu.org
     Ever confirmed|0                           |1
   Target Milestone|---                         |13.3
           Keywords|                            |needs-bisection, wrong-code
            Summary|Miscompilation: A possible  |[13/14 Regression]
                   |miscompilation in GCC 13    |Miscompilation: A possible
                   |and 14 with option -Os      |miscompilation in GCC 13
                   |                            |and 14 with option -Os
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
final value replacement:
  c_7 = PHI <c_2(4)>
 with expr: b_3(D) != 0 ? 32 - __builtin_clz ((unsigned int) b_3(D)) : 24

24 is definitely wrong here. It should have been 0.

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

* [Bug tree-optimization/114203] [13/14 Regression] Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
  2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
  2024-03-02  4:40 ` [Bug tree-optimization/114203] [13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-03-04  9:36 ` rguenth at gcc dot gnu.org
  2024-03-04 10:45 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-04  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
  (set_nb_iterations_in_loop = b_3(D) != 0 ? (unsigned int) (32 - __builtin_clz
((unsigned int) b_3(D))) : 24))

The issue is for prec <= i_prec we do

     call = build_call_expr (fn, 1, src);
      if (define_at_zero)
        {
          tree is_zero = fold_build2 (NE_EXPR, boolean_type_node, src,
                                      build_zero_cst (TREE_TYPE (src)));
          call = fold_build3 (COND_EXPR, integer_type_node, is_zero, call,
                              build_int_cst (integer_type_node, prec));
        }

      if (leading && prec < i_prec)
        call = fold_build2 (MINUS_EXPR, integer_type_node, call,
                            build_int_cst (integer_type_node, i_prec - prec));

but that's the wrong way around, 'define_at_zero' should happen after the
adjustment for leading.

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

* [Bug tree-optimization/114203] [13/14 Regression] Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
  2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
  2024-03-02  4:40 ` [Bug tree-optimization/114203] [13/14 Regression] " pinskia at gcc dot gnu.org
  2024-03-04  9:36 ` rguenth at gcc dot gnu.org
@ 2024-03-04 10:45 ` cvs-commit at gcc dot gnu.org
  2024-03-04 10:46 ` [Bug tree-optimization/114203] [13 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-04 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

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

commit r14-9293-gcde50296a19b109909089b91d532d2c8455f5f10
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Mar 4 10:38:31 2024 +0100

    tree-optimization/114203 - wrong CLZ niter computation

    For precision less than int we apply the adjustment to make it defined
    at zero after the adjustment to make it compute CLZ rather than CTZ.
    That's wrong.

            PR tree-optimization/114203
            * tree-ssa-loop-niter.cc (build_cltz_expr): Apply CTZ->CLZ
            adjustment before making the result defined at zero.

            * gcc.dg/torture/pr114203.c: New testcase.

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

* [Bug tree-optimization/114203] [13 Regression] Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
  2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
                   ` (2 preceding siblings ...)
  2024-03-04 10:45 ` cvs-commit at gcc dot gnu.org
@ 2024-03-04 10:46 ` rguenth at gcc dot gnu.org
  2024-03-21 11:49 ` cvs-commit at gcc dot gnu.org
  2024-03-21 11:51 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-04 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |14.0
            Summary|[13/14 Regression]          |[13 Regression]
                   |Miscompilation: A possible  |Miscompilation: A possible
                   |miscompilation in GCC 13    |miscompilation in GCC 13
                   |and 14 with option -Os      |and 14 with option -Os
      Known to fail|                            |13.2.0
           Priority|P3                          |P2

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

* [Bug tree-optimization/114203] [13 Regression] Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
  2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
                   ` (3 preceding siblings ...)
  2024-03-04 10:46 ` [Bug tree-optimization/114203] [13 " rguenth at gcc dot gnu.org
@ 2024-03-21 11:49 ` cvs-commit at gcc dot gnu.org
  2024-03-21 11:51 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-21 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

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

commit r13-8482-ga729b1227bc8c84cd91a3b8c9c9d11bc43d415de
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Mar 4 10:38:31 2024 +0100

    tree-optimization/114203 - wrong CLZ niter computation

    For precision less than int we apply the adjustment to make it defined
    at zero after the adjustment to make it compute CLZ rather than CTZ.
    That's wrong.

            PR tree-optimization/114203
            * tree-ssa-loop-niter.cc (build_cltz_expr): Apply CTZ->CLZ
            adjustment before making the result defined at zero.

            * gcc.dg/torture/pr114203.c: New testcase.

    (cherry picked from commit cde50296a19b109909089b91d532d2c8455f5f10)

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

* [Bug tree-optimization/114203] [13 Regression] Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os
  2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
                   ` (4 preceding siblings ...)
  2024-03-21 11:49 ` cvs-commit at gcc dot gnu.org
@ 2024-03-21 11:51 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-21 11:51 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |13.2.1
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.  Thanks for reporting.

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

end of thread, other threads:[~2024-03-21 11:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-02  4:19 [Bug c/114203] New: Miscompilation: A possible miscompilation in GCC 13 and 14 with option -Os 141242068 at smail dot nju.edu.cn
2024-03-02  4:40 ` [Bug tree-optimization/114203] [13/14 Regression] " pinskia at gcc dot gnu.org
2024-03-04  9:36 ` rguenth at gcc dot gnu.org
2024-03-04 10:45 ` cvs-commit at gcc dot gnu.org
2024-03-04 10:46 ` [Bug tree-optimization/114203] [13 " rguenth at gcc dot gnu.org
2024-03-21 11:49 ` cvs-commit at gcc dot gnu.org
2024-03-21 11:51 ` rguenth 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).