From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id B223A3847700 for ; Wed, 3 Apr 2024 07:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B223A3847700 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B223A3847700 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712130207; cv=none; b=MCLde75U7jutefS1wz91BMcisYwwEDXKmioZxy49+5IfRfvAcRWxkmcKR4dX631M9bLVekdEi2dvhbibjU9tqfGYtOdf6gctmlFFYCcmShk8mt4p5+tWh8lhRtBSmQPAgzdtdICEZlZGeqX/nEFPLYHxqQxw5JBllZ1V3Q6ygXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712130207; c=relaxed/simple; bh=vv4RqMBGADZh7FlP54HUZsPa2hcM5UP9AejC1nTCDTM=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=DjvqMpt8FqR4UyOqAhH6fGk0/XK/4WOsrM0+HOWVi1DwNbC6qzYPL0xkKhNjt8EW/uLsWaGiiv/AsNueH+m++8G97r6cSLmsFb7cBqKnccRvw5eaoCkezDcxCV6GxmD3gJxUoRS3eMjUA35ZCYaZsLgwffU/AGS94KQseZFZeXw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8AD195C96B; Wed, 3 Apr 2024 07:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712130203; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8CQgbzz9EwfsR58cMuvOttQ+hSb8F3AHDyf4aH0QVuE=; b=dICuzHbmz4hfCERUKpvG4aeJ9YMsAkWNlFZ9MHOn7gNgM0QYNznVh2SBbz6Mlj/Lg69RSY iUlG4LeghchhYrioyGLNbx/NgXCGPQ2loXRNSppocM1INL2BpGbPsO+n40TIiyoYBFjAUa 0lzjm3RVlfhQopl4jY355OvUBlA/zSo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712130203; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=8CQgbzz9EwfsR58cMuvOttQ+hSb8F3AHDyf4aH0QVuE=; b=ddPBH4PLitwY5MBH4gWuW8TJxpHgF1U6xpoP8Bp4vao3OFfgdr4ekPh8+6c95aTLxaTZVl gBZNbit29xE/hzAQ== Authentication-Results: smtp-out2.suse.de; none Date: Wed, 3 Apr 2024 09:43:23 +0200 (CEST) From: Richard Biener To: Jakub Jelinek cc: Jeff Law , Eric Botcazou , gcc-patches@gcc.gnu.org, Roger Sayle Subject: Re: [PATCH] expr: Fix up emit_push_insn [PR114552] In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Score: -1.14 X-Spamd-Result: default: False [-1.14 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(2.96)[0.986]; NEURAL_HAM_LONG(-1.00)[-0.999]; RCPT_COUNT_FIVE(0.00)[5]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,expr.cc:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com,adacore.com,gcc.gnu.org,nextmovesoftware.com]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_STOCKGEN,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 3 Apr 2024, Jakub Jelinek wrote: > Hi! > > r13-990 added optimizations in multiple spots to optimize during > expansion storing of constant initializers into targets. > In the load_register_parameters and expand_expr_real_1 cases, > it checks it has a tree as the source and so knows we are reading > that whole decl's value, so the code is fine as is, but in the > emit_push_insn case it checks for a MEM from which something > is pushed and checks for SYMBOL_REF as the MEM's address, but > still assumes the whole object is copied, which as the following > testcase shows might not always be the case. In the testcase, > k is 6 bytes, then 2 bytes of padding, then another 4 bytes, > while the emit_push_insn wants to store just the 6 bytes. > > The following patch simply verifies it is the whole initializer > that is being stored, I think that is best thing to do so late > in GCC 14 cycle as well for backporting. > > For GCC 15, perhaps the code could stop requiring it must be at offset zero, > nor that the size is a subset, but could use > get_symbol_constant_value/fold_ctor_reference gimple-fold APIs to actually > extract just part of the initializer if we e.g. push just some subset > (of course, still verify that it is a subset). For sizes which are power > of two bytes and we have some integer modes, we could use as type for > fold_ctor_reference corresponding integral types, otherwise dunno, punt > or use some structure (e.g. try to find one in the initializer?), whatever. > But even in the other spots it could perhaps handle loading of > COMPONENT_REFs or MEM_REFs from the .rodata vars. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. Thanks, Richard. > 2024-04-02 Jakub Jelinek > > PR middle-end/114552 > * expr.cc (emit_push_insn): Only use store_constructor for > immediate_const_ctor_p if int_expr_size matches size. > > * gcc.c-torture/execute/pr114552.c: New test. > > --- gcc/expr.cc.jj 2024-03-15 10:10:51.209237835 +0100 > +++ gcc/expr.cc 2024-04-02 16:01:39.566744302 +0200 > @@ -5466,6 +5466,7 @@ emit_push_insn (rtx x, machine_mode mode > /* If source is a constant VAR_DECL with a simple constructor, > store the constructor to the stack instead of moving it. */ > const_tree decl; > + HOST_WIDE_INT sz; > if (partial == 0 > && MEM_P (xinner) > && SYMBOL_REF_P (XEXP (xinner, 0)) > @@ -5473,9 +5474,11 @@ emit_push_insn (rtx x, machine_mode mode > && VAR_P (decl) > && TREE_READONLY (decl) > && !TREE_SIDE_EFFECTS (decl) > - && immediate_const_ctor_p (DECL_INITIAL (decl), 2)) > - store_constructor (DECL_INITIAL (decl), target, 0, > - int_expr_size (DECL_INITIAL (decl)), false); > + && immediate_const_ctor_p (DECL_INITIAL (decl), 2) > + && (sz = int_expr_size (DECL_INITIAL (decl))) > 0 > + && CONST_INT_P (size) > + && INTVAL (size) == sz) > + store_constructor (DECL_INITIAL (decl), target, 0, sz, false); > else > emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM); > } > --- gcc/testsuite/gcc.c-torture/execute/pr114552.c.jj 2024-04-02 16:08:12.959366793 +0200 > +++ gcc/testsuite/gcc.c-torture/execute/pr114552.c 2024-04-02 16:03:49.829963659 +0200 > @@ -0,0 +1,24 @@ > +/* PR middle-end/114552 */ > + > +struct __attribute__((packed)) S { short b; int c; }; > +struct T { struct S b; int e; }; > +static const struct T k = { { 1, 0 }, 0 }; > + > +__attribute__((noinline)) void > +foo (void) > +{ > + asm volatile ("" : : : "memory"); > +} > + > +__attribute__((noinline)) void > +bar (struct S n) > +{ > + foo (); > +} > + > +int > +main () > +{ > + bar (k.b); > + return 0; > +} > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)