public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/114347] wrong constant folding when casting __bf16 to int
Date: Fri, 15 Mar 2024 09:03:16 +0000	[thread overview]
Message-ID: <bug-114347-4-PkiEQt965r@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114347-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |jsm28 at gcc dot gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I suspect we fail to round at parsing time.  I see we get to see

 <excess_precision_expr 0x7ffff6bb6500
    type <real_type 0x7ffff6a33888 __bf16 BF
        size <integer_cst 0x7ffff6a2d108 constant 16>
        unit-size <integer_cst 0x7ffff6a2d120 constant 2>
        align:16 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6a33888 precision:16>

    arg:0 <real_cst 0x7ffff6be06f0
        type <real_type 0x7ffff6a332a0 float SF
            size <integer_cst 0x7ffff6a2d198 constant 32>
            unit-size <integer_cst 0x7ffff6a2d1b0 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6a332a0 precision:32
            pointer_to_this <pointer_type 0x7ffff6a33930>>
        constant 2.57e+2>

and then upon processing the (int) cast simply strip the excess_precision_expr.

#0  convert (type=<integer_type 0x7ffff6a2b5e8 int>, 
    expr=<real_cst 0x7ffff6be0930>)
    at /home/rguenther/src/trunk/gcc/c/c-convert.cc:253
#1  0x0000000000d8e9e2 in build_c_cast (loc=263296, 
    type=<integer_type 0x7ffff6a2b5e8 int>, expr=<real_cst 0x7ffff6be0930>)
    at /home/rguenther/src/trunk/gcc/c/c-typeck.cc:6387
#2  0x0000000000d8f01c in c_cast_expr (loc=263296, type_name=0x46c6760, 
    expr=<excess_precision_expr 0x7ffff6bb6640>)
    at /home/rguenther/src/trunk/gcc/c/c-typeck.cc:6461

/* Build an expression representing a cast to type TYPE of expression EXPR.
   LOC is the location of the cast-- typically the open paren of the cast.  */

tree
build_c_cast (location_t loc, tree type, tree expr)
{
  tree value;

  bool int_operands = EXPR_INT_CONST_OPERANDS (expr);

  if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR)
    expr = TREE_OPERAND (expr, 0);


But maybe that's correct behavior here?  Or we shouldn't have an
excess_precision_expr in the first place for BF16?

  parent reply	other threads:[~2024-03-15  9:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15  4:55 [Bug c/114347] New: " eggert at cs dot ucla.edu
2024-03-15  5:01 ` [Bug middle-end/114347] " pinskia at gcc dot gnu.org
2024-03-15  5:19 ` eggert at cs dot ucla.edu
2024-03-15  9:03 ` rguenth at gcc dot gnu.org [this message]
2024-03-15 16:58 ` jsm28 at gcc dot gnu.org
2024-03-18  8:03 ` rguenth at gcc dot gnu.org
2024-03-18  8:16 ` jakub at gcc dot gnu.org
2024-03-18  8:53 ` rguenth at gcc dot gnu.org
2024-03-18  9:06 ` jakub at gcc dot gnu.org
2024-03-18  9:08 ` liuhongt at gcc dot gnu.org
2024-03-20  6:02 ` eggert at cs dot ucla.edu
2024-03-20  6:19 ` pinskia at gcc dot gnu.org
2024-03-21  0:48 ` cvs-commit at gcc dot gnu.org
2024-03-25 22:21 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114347-4-PkiEQt965r@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).