public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Avoid duplicate vector initializations during RTL expansion.
@ 2023-06-11 16:15 Roger Sayle
  2023-06-12 22:37 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2023-06-11 16:15 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1316 bytes --]


This middle-end patch avoids some redundant RTL for vector initialization
during RTL expansion.  For the simple test case:

typedef __int128 v1ti __attribute__ ((__vector_size__ (16)));
__int128 key;

v1ti foo() {
    return (v1ti){key};
}

the middle-end currently expands:

(set (reg:V1TI 85) (const_vector:V1TI [ (const_int 0) ]))

(set (reg:V1TI 85) (mem/c:V1TI (symbol_ref:DI ("key"))))

where we create a dead instruction that initializes the vector to zero,
immediately followed by a set of the entire vector.  This patch skips
this zeroing instruction when the vector has only a single element.
It also updates the code to indicate when we've cleared the vector,
so that we don't need to initialize zero elements.

Interestingly, this code is very similar to my patch from April 2006:
https://gcc.gnu.org/pipermail/gcc-patches/2006-April/192861.html


This patch has been tested on x86_64-pc-linux-gnu with a make bootstrap
and make -k check, both with and without --target_board=unix{-m32}, with
no new failures.  Ok for mainline?


2023-06-11  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        * expr.cc (store_constructor) <case VECTOR_TYPE>: Don't bother
        clearing vectors with only a single element.  Set CLEARED if the
        vector was initialized to zero.


Thanks,
Roger
--


[-- Attachment #2: patchvi.txt --]
[-- Type: text/plain, Size: 593 bytes --]

diff --git a/gcc/expr.cc b/gcc/expr.cc
index 868fa6e..62cd8fa 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -7531,8 +7531,11 @@ store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
 	  }
 
 	/* Inform later passes that the old value is dead.  */
-	if (!cleared && !vector && REG_P (target))
-	  emit_move_insn (target, CONST0_RTX (mode));
+	if (!cleared && !vector && REG_P (target) && maybe_gt (n_elts, 1u))
+	  {
+	    emit_move_insn (target, CONST0_RTX (mode));
+	    cleared = 1;
+	  }
 
         if (MEM_P (target))
 	  alias = MEM_ALIAS_SET (target);

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

* Re: [PATCH] Avoid duplicate vector initializations during RTL expansion.
  2023-06-11 16:15 [PATCH] Avoid duplicate vector initializations during RTL expansion Roger Sayle
@ 2023-06-12 22:37 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-06-12 22:37 UTC (permalink / raw)
  To: Roger Sayle, gcc-patches



On 6/11/23 10:15, Roger Sayle wrote:
> 
> This middle-end patch avoids some redundant RTL for vector initialization
> during RTL expansion.  For the simple test case:
> 
> typedef __int128 v1ti __attribute__ ((__vector_size__ (16)));
> __int128 key;
> 
> v1ti foo() {
>      return (v1ti){key};
> }
> 
> the middle-end currently expands:
> 
> (set (reg:V1TI 85) (const_vector:V1TI [ (const_int 0) ]))
> 
> (set (reg:V1TI 85) (mem/c:V1TI (symbol_ref:DI ("key"))))
> 
> where we create a dead instruction that initializes the vector to zero,
> immediately followed by a set of the entire vector.  This patch skips
> this zeroing instruction when the vector has only a single element.
> It also updates the code to indicate when we've cleared the vector,
> so that we don't need to initialize zero elements.
> 
> Interestingly, this code is very similar to my patch from April 2006:
> https://gcc.gnu.org/pipermail/gcc-patches/2006-April/192861.html
> 
> 
> This patch has been tested on x86_64-pc-linux-gnu with a make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}, with
> no new failures.  Ok for mainline?
> 
> 
> 2023-06-11  Roger Sayle  <roger@nextmovesoftware.com>
> 
> gcc/ChangeLog
>          * expr.cc (store_constructor) <case VECTOR_TYPE>: Don't bother
>          clearing vectors with only a single element.  Set CLEARED if the
>          vector was initialized to zero.
Funny how old (unresolved) issues will often raise their ugly heads again!

OK for the trunk.

jeff

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

end of thread, other threads:[~2023-06-12 22:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-11 16:15 [PATCH] Avoid duplicate vector initializations during RTL expansion Roger Sayle
2023-06-12 22:37 ` Jeff Law

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).