diff mbox series

rtl-optimization: Fix uninitialized use of opaque mode variable ICE [PR98872]

Message ID c985c6e8-2023-27cb-a9e8-2e466617988b@linux.ibm.com
State New
Headers show
Series rtl-optimization: Fix uninitialized use of opaque mode variable ICE [PR98872] | expand

Commit Message

Peter Bergner Feb. 12, 2021, 10:21 p.m. UTC
On 2/8/21 7:29 AM, Segher Boessenkool wrote:
>> I think we should either add a new rtx code for constant opaque modes
>> or make init-regs just emit the clobber for opaque modes (and not emit
>> the move).
> 
> Thanks for looking Richard.  That last option sounds good to me as well.

Ok, guarding the emit_move_insn with a CONST0_RTX test which causes us
to only emit the clobber for opaque modes fixes the problem.  Nice!
That means we can eliminate the rest of the patch other than the test case!



>>> --- /dev/null
>>> +++ b/gcc/testsuite/gcc.target/powerpc/pr98872.c
>>> @@ -0,0 +1,20 @@
>>> +/* PR target/98872 */
>>> +/* { dg-do compile } */
>>> +/* { dg-require-effective-target power10_ok } */
>>> +/* { dg-options "-O2 -mdejagnu-cpu=power10" } */
>>> +
>>> +/* Verify we do not ICE on the tests below.  */
> 
> Do the existing tests already check the expected code for this?

Yes, our mma-builtin-*.c tests check for expected output.



The updated patch below fixes the bug too and is much simpler! :-)


rtl-optimization: Fix uninitialized use of opaque mode variable ICE [PR98872]

The initialize_uninitialized_regs function emits (set (reg:) (CONST0_RTX))
for all uninitialized pseudo uses.  However, some modes (eg, opaque modes)
may not have a CONST0_RTX defined, leading to an ICE when we try and create
the initialization insn.  The fix is to skip emitting the initialization
if there is no CONST0_RTX defined for the mode.

This following patch fixes the ICE and is currently regtesting.
Ok for trunk if the bootstrap and regtesting come back clean?

Peter


2021-02-12  Peter Bergner  <bergner@linux.ibm.com>

gcc/
	PR rtl-optimization/98872
	* init-regs.c (initialize_uninitialized_regs): Skip initialization
	if CONST0_RTX is NULL.

gcc/testsuite/
	PR rtl-optimization/98872
	* gcc.target/powerpc/pr98872.c: New test.

Comments

Peter Bergner Feb. 12, 2021, 11:30 p.m. UTC | #1
On 2/12/21 4:21 PM, Peter Bergner wrote:
> rtl-optimization: Fix uninitialized use of opaque mode variable ICE [PR98872]
> 
> The initialize_uninitialized_regs function emits (set (reg:) (CONST0_RTX))
> for all uninitialized pseudo uses.  However, some modes (eg, opaque modes)
> may not have a CONST0_RTX defined, leading to an ICE when we try and create
> the initialization insn.  The fix is to skip emitting the initialization
> if there is no CONST0_RTX defined for the mode.
> 
> This following patch fixes the ICE and is currently regtesting.
> Ok for trunk if the bootstrap and regtesting come back clean?
> 
> Peter
> 
> 
> 2021-02-12  Peter Bergner  <bergner@linux.ibm.com>
> 
> gcc/
> 	PR rtl-optimization/98872
> 	* init-regs.c (initialize_uninitialized_regs): Skip initialization
> 	if CONST0_RTX is NULL.
> 
> gcc/testsuite/
> 	PR rtl-optimization/98872
> 	* gcc.target/powerpc/pr98872.c: New test.

Testing came back clean with no regressions.

Peter
Richard Sandiford Feb. 15, 2021, 12:25 p.m. UTC | #2
Peter Bergner <bergner@linux.ibm.com> writes:
> 2021-02-12  Peter Bergner  <bergner@linux.ibm.com>
>
> gcc/
> 	PR rtl-optimization/98872
> 	* init-regs.c (initialize_uninitialized_regs): Skip initialization
> 	if CONST0_RTX is NULL.
>
> gcc/testsuite/
> 	PR rtl-optimization/98872
> 	* gcc.target/powerpc/pr98872.c: New test.

OK, thanks.

Richard
Peter Bergner Feb. 15, 2021, 4:40 p.m. UTC | #3
On 2/15/21 6:25 AM, Richard Sandiford wrote:
> Peter Bergner <bergner@linux.ibm.com> writes:
>> 2021-02-12  Peter Bergner  <bergner@linux.ibm.com>
>>
>> gcc/
>> 	PR rtl-optimization/98872
>> 	* init-regs.c (initialize_uninitialized_regs): Skip initialization
>> 	if CONST0_RTX is NULL.
>>
>> gcc/testsuite/
>> 	PR rtl-optimization/98872
>> 	* gcc.target/powerpc/pr98872.c: New test.
> 
> OK, thanks.

Ok, patch pushed to mainline.  Thanks!

Peter
diff mbox series

Patch

diff --git a/gcc/init-regs.c b/gcc/init-regs.c
index 903c6541f10..72e898f3e33 100644
--- a/gcc/init-regs.c
+++ b/gcc/init-regs.c
@@ -105,7 +105,10 @@  initialize_uninitialized_regs (void)
 
 		  start_sequence ();
 		  emit_clobber (reg);
-		  emit_move_insn (reg, CONST0_RTX (GET_MODE (reg)));
+		  /* PR98872: Only emit an initialization if MODE has a
+		     CONST0_RTX defined.  */
+		  if (CONST0_RTX (GET_MODE (reg)))
+		    emit_move_insn (reg, CONST0_RTX (GET_MODE (reg)));
 		  move_insn = get_insns ();
 		  end_sequence ();
 		  emit_insn_before (move_insn, insn);
diff --git a/gcc/testsuite/gcc.target/powerpc/pr98872.c b/gcc/testsuite/gcc.target/powerpc/pr98872.c
new file mode 100644
index 00000000000..f33ad9b48b6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr98872.c
@@ -0,0 +1,19 @@ 
+/* PR target/98872 */
+/* { dg-require-effective-target power10_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power10" } */
+
+/* Verify we do not ICE on the following tests.  */
+
+void
+foo (__vector_quad *dst)
+{
+  __vector_quad acc;
+  *dst = acc;
+}
+
+void
+bar (__vector_pair *dst)
+{
+  __vector_pair pair;
+  *dst = pair;
+}