From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0BB0C385841D; Wed, 1 Dec 2021 17:17:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BB0C385841D From: "qinzhao at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: qinzhao at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2021 17:17:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103271 --- 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.=20 For the following call to .DEFERRED_INIT: MEM[(int[0:D.1492] *)&fb.3] =3D .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_ba= se)" 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.=20 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, s= uch 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) unit-size align:32 warn_if_not_align:0 symtab:0 alias-set 1 canonical-type 0x7ffff07465e8 precision:32 min max pointer_to_this > sizes-gimplified type_1 BLK size =20=20=20=20=20=20=20=20 used unsigned ignored TI t.c:8:7=20 size unit-size align:128 warn_if_not_align:0 context > unit-size used unsigned ignored DI t.c:8:7 size unit-size align:64 warn_if_not_align:0 context > align:32 warn_if_not_align:0 symtab:0 alias-set -1 structural-equal= ity domain sizes-gimplified DI size unit-s= ize align:64 warn_if_not_align:0 symtab:0 alias-set -1 structural-equality precision:64 min max > pointer_to_this > nothrow arg:0 unsigned DI size unit-size align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-ty= pe 0x7ffff082c2a0> arg:0 used ignored TI t.c:8:7 size unit-size align:64 warn_if_not_align:0 context (reg:TI 72 [ fb.3 ])>> arg:1 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=20 arg:0 used ignored TI t.c:8:7 size unit-size align:64 warn_if_not_align:0 context (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.=20 My suspicion is, -mno-strict-align applied some kind of optimization that t= urn the var_decl from:=20 arg:0 used ignored BLK t.c:8:7 size unit-size align:128 warn_if_not_align:0 context (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 used ignored TI t.c:8:7 size unit-size align:64 warn_if_not_align:0 context (reg:TI 72 [ fb.3 ])>> However, the TREE_TYPE of MEM[(int[0:D.1492] *)&fb.3] is not updated accordingly.=