public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "qinzhao at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/103271] ICE in assign_stack_temp_for_type with -ftrivial-auto-var-init=pattern and VLAs and -mno-strict-align on riscv64
Date: Wed, 01 Dec 2021 17:17:14 +0000	[thread overview]
Message-ID: <bug-103271-4-ga8FbmUvHM@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103271-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from qinzhao at gcc dot gnu.org ---
the minimum option to repeat this failure is "-O1 -mno-strict-align".

The option "-mno-strict-align" is the one that make the difference. 

For the following call to .DEFERRED_INIT:

MEM[(int[0:D.1492] *)&fb.3] = .DEFERRED_INIT (16, 1, 1);

the LHS is MEM[(int[0:D.1492] *)&fb.3].

When -mno-strict-align is NOT present, "mem_ref_refers_to_non_mem_p (lhs_base)"
return FALSE, lHS is considered as MEM, and the call is expanded through
"memset" path. No issue.

when -mno-strict-align is present, "mem_ref_refers_to_non_mem_p (lhs_base)"
return TRUE, as a result, LHS is considered to be put into a register, and then
the call is expanded through "expand_assignment" path. 

The major issue during expanding through "expand_assignment" path is:

although the LHS "MEM[(int[0:D.1492] *)&fb.3]" is decided to be put into
register with TI mode, however, the TREE_TYPE of LHS is still a VLA type, such
inconsistency in IR cause the final ICE.

with the option -mno-strict-align, the IR of lhs_base is:

(gdb) call debug_tree(lhs_base)
 <mem_ref 0x7ffff082bc08
    type <array_type 0x7ffff082cb28
        type <integer_type 0x7ffff07465e8 int sizes-gimplified public SI
            size <integer_cst 0x7ffff0739bb8 constant 32>
            unit-size <integer_cst 0x7ffff0739bd0 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set 1 canonical-type
0x7ffff07465e8 precision:32 min <integer_cst 0x7ffff0739b70 -2147483648> max
<integer_cst 0x7ffff0739b88 2147483647>
            pointer_to_this <pointer_type 0x7ffff074d9d8>>
        sizes-gimplified type_1 BLK
        size <var_decl 0x7ffff7ff0360 D.1495 type <integer_type 0x7ffff07460a8
bitsizetype>        
            used unsigned ignored TI t.c:8:7 
            size <integer_cst 0x7ffff07399c0 constant 128>
            unit-size <integer_cst 0x7ffff07399d8 constant 16>
            align:128 warn_if_not_align:0 context <function_decl 0x7ffff0830500
qy>>
        unit-size <var_decl 0x7ffff7ff03f0 D.1496 type <integer_type
0x7ffff0746000 sizetype>
            used unsigned ignored DI t.c:8:7
            size <integer_cst 0x7ffff0739978 constant 64>
            unit-size <integer_cst 0x7ffff0739990 constant 8>
            align:64 warn_if_not_align:0 context <function_decl 0x7ffff0830500
qy>>
        align:32 warn_if_not_align:0 symtab:0 alias-set -1 structural-equality
        domain <integer_type 0x7ffff082ca80 type <integer_type 0x7ffff0746000
sizetype>
            sizes-gimplified DI size <integer_cst 0x7ffff0739978 64> unit-size
<integer_cst 0x7ffff0739990 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1
structural-equality precision:64 min <integer_cst 0x7ffff07399a8 0> max
<var_decl 0x7ffff7ff02d0 D.1494>>
        pointer_to_this <pointer_type 0x7ffff082cbd0>>
    nothrow
    arg:0 <addr_expr 0x7ffff082e7e0
        type <pointer_type 0x7ffff082c2a0 type <array_type 0x7ffff082c1f8>
            unsigned DI size <integer_cst 0x7ffff0739978 64> unit-size
<integer_cst 0x7ffff0739990 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff082c2a0>

        arg:0 <var_decl 0x7ffff7ff0990 fb.3 type <array_type 0x7ffff082c1f8>
            used ignored TI t.c:8:7 size <integer_cst 0x7ffff07399c0 128>
unit-size <integer_cst 0x7ffff07399d8 16>
            align:64 warn_if_not_align:0 context <function_decl 0x7ffff0830500
qy>
            (reg:TI 72 [ fb.3 ])>>
    arg:1 <integer_cst 0x7ffff0836fd8 type <pointer_type 0x7ffff082cbd0>
constant 0>
    t.c:8:7 start: t.c:8:7 finish: t.c:8:8>

>From the above IR, we can see,

1. the base address of this mem_ref is 

        arg:0 <var_decl 0x7ffff7ff0990 fb.3 type <array_type 0x7ffff082c1f8>
            used ignored TI t.c:8:7 size <integer_cst 0x7ffff07399c0 128>
unit-size <integer_cst 0x7ffff07399d8 16>
            align:64 warn_if_not_align:0 context <function_decl 0x7ffff0830500
qy>
            (reg:TI 72 [ fb.3 ])>>

which is in register of TI mode;

2. However, the TREE_TYPE of this mem_ref is still a VLA type.

when call "build_zero_cst (var_type)", the var_type is a VLA type, therefore
the ICE. 


My suspicion is, -mno-strict-align applied some kind of optimization that turn
the var_decl from: 

        arg:0 <var_decl 0x7ffff7ff0990 fb.3 type <array_type 0x7ffff082c1f8>
            used ignored BLK t.c:8:7 size <integer_cst 0x7ffff07399c0 128>
unit-size <integer_cst 0x7ffff07399d8 16>
            align:128 warn_if_not_align:0 context <function_decl 0x7ffff0830500
qy>
            (mem/c:BLK (plus:DI (reg/f:DI 67 virtual-stack-vars)
        (const_int -16 [0xfffffffffffffff0])) [0 fb.3+0 S16 A128])>>

to:
        arg:0 <var_decl 0x7ffff7ff0990 fb.3 type <array_type 0x7ffff082c1f8>
            used ignored TI t.c:8:7 size <integer_cst 0x7ffff07399c0 128>
unit-size <integer_cst 0x7ffff07399d8 16>
            align:64 warn_if_not_align:0 context <function_decl 0x7ffff0830500
qy>
            (reg:TI 72 [ fb.3 ])>>


However, the TREE_TYPE of MEM[(int[0:D.1492] *)&fb.3] is not updated
accordingly.

  parent reply	other threads:[~2021-12-01 17:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  8:55 [Bug target/103271] New: ICE in assign_stack_temp_for_type, at function.c:798 marxin at gcc dot gnu.org
2021-11-16  8:55 ` [Bug target/103271] " marxin at gcc dot gnu.org
2021-11-16  9:39 ` rguenth at gcc dot gnu.org
2021-11-22 23:17 ` [Bug target/103271] ICE in assign_stack_temp_for_type with -ftrivial-auto-var-init=pattern and VLAs and -mno-strict-align on riscv64 qinzhao at gcc dot gnu.org
2021-11-23  7:33 ` marxin at gcc dot gnu.org
2021-11-23  7:47 ` rguenther at suse dot de
2021-11-23 16:22 ` qing.zhao at oracle dot com
2021-11-26  5:08 ` wilson at gcc dot gnu.org
2021-11-26  5:20 ` wilson at gcc dot gnu.org
2021-11-26  7:16 ` rguenther at suse dot de
2021-12-01 17:17 ` qinzhao at gcc dot gnu.org [this message]
2021-12-01 19:46 ` qinzhao at gcc dot gnu.org
2021-12-01 22:31 ` qinzhao at gcc dot gnu.org
2021-12-02  9:07 ` rguenth at gcc dot gnu.org
2021-12-02  9:29 ` rguenth at gcc dot gnu.org
2021-12-02 12:35 ` cvs-commit at gcc dot gnu.org
2021-12-02 12:36 ` rguenth at gcc dot gnu.org
2021-12-02 16:12 ` qinzhao at gcc dot gnu.org
2021-12-02 17:47 ` wilson at gcc dot gnu.org
2021-12-02 22:19 ` qinzhao at gcc dot gnu.org
2021-12-03 23:08 ` wilson 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-103271-4-ga8FbmUvHM@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).