public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH PR62151]Fix uninitialized register issue caused by distribute_notes in combine pass
@ 2014-08-27 10:08 Bin Cheng
  2014-08-27 10:34 ` Richard Earnshaw
  0 siblings, 1 reply; 26+ messages in thread
From: Bin Cheng @ 2014-08-27 10:08 UTC (permalink / raw)
  To: gcc-patches

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

Hi
As reported in bug pr62151, combine pass may wrongly delete necessary
instruction in function distribute_notes thus leaving register
uninitialized.  This patch is to fix the issue by checking if i2 immediately
modifies the register in REG_DEAD note.  If yes, set tem_insn accordingly to
start finding right place for note distribution from i2.

I once sent a RFC patch at
https://gcc.gnu.org/ml/gcc-patches/2014-08/msg01718.html, but got no
comments,  here I added some comments in this patch to make it a formal one.


I tested the original patch, and will re-test it against the latest code
later.  So is it OK?  Any comments will be appreciated.

Thanks,
bin

2014-08-27  Bin Cheng  <bin.cheng@arm.com>

	PR rtl-optimization/62151
	* combine.c (distribute_notes): Check i2 if it modifies register
	in REG_DEAD note immediately, set tem_insn accordingly.

[-- Attachment #2: pr62151-20140827.txt --]
[-- Type: text/plain, Size: 1370 bytes --]

Index: gcc/combine.c
===================================================================
--- gcc/combine.c	(revision 214413)
+++ gcc/combine.c	(working copy)
@@ -13499,7 +13499,38 @@ distribute_notes (rtx notes, rtx_insn *from_insn,
 		       || rtx_equal_p (XEXP (note, 0), elim_i1)
 		       || rtx_equal_p (XEXP (note, 0), elim_i0))
 		break;
-	      tem_insn = i3;
+
+	      /* See PR62151.
+		 It's possible to have below situation:
+		   i0: r1 <- const_0
+		   i1: r2 <- r1 op_1 const_1
+		       REG_DEAD r1
+		   i2: r1 <- r2 op_2 const_2
+		       REG_DEAD r2
+		   i3: r3 <- r1
+		   i4: r4 <- r1
+
+		 It is transformed into below code before distributing
+		 the REG_DEAD note in i1:
+		   i0: NOTE_INSN_DELETED
+		   i1: NOTE_INSN_DELETED
+		   i2: r1 <- const_combined
+		   i3: r3 <- const_combined
+		   i4: r4 <- r1
+
+		 We need to check if i2 immediately modifies r1 otherwise
+		 i2 would be deleted by below code when distributing
+		 REG_DEAD note, leaving r1 in i4 uninitialied.
+
+		 We set TEM_INSN to i2 for this case indicating that we
+		 need to find right place for distribution from i2.
+		 */
+	      if (from_insn && i2
+		  && from_insn != i2 && from_insn != i3
+		  && reg_set_p (XEXP (note, 0), PATTERN (i2)))
+		tem_insn = i2;
+	      else
+		tem_insn = i3;
 	    }
 
 	  if (place == 0)

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

end of thread, other threads:[~2014-09-05  4:17 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-27 10:08 [PATCH PR62151]Fix uninitialized register issue caused by distribute_notes in combine pass Bin Cheng
2014-08-27 10:34 ` Richard Earnshaw
2014-08-28  5:04   ` Bin.Cheng
2014-08-30  5:58     ` Jeff Law
2014-08-31 12:19       ` Segher Boessenkool
2014-09-01  3:36         ` Bin.Cheng
2014-09-01 11:39           ` Segher Boessenkool
2014-09-01 16:52             ` Jeff Law
2014-09-01 17:50               ` Segher Boessenkool
2014-09-02  2:02                 ` Bin.Cheng
2014-09-02 11:40                   ` Segher Boessenkool
2014-09-02  3:35                 ` Jeff Law
2014-09-02 12:10                 ` Ulrich Weigand
2014-09-02 13:41                   ` Segher Boessenkool
2014-09-03  2:36                     ` Bin.Cheng
2014-09-03 13:21                       ` Segher Boessenkool
2014-09-01 16:52         ` Jeff Law
2014-09-01 19:16           ` Segher Boessenkool
2014-09-02  3:28             ` Jeff Law
2014-09-02  5:18               ` Bin.Cheng
2014-09-05  4:17                 ` Jeff Law
2014-09-02 11:50               ` Segher Boessenkool
2014-09-01  4:18       ` Bin.Cheng
2014-09-02  3:40         ` Jeff Law
2014-09-02  5:15           ` Bin.Cheng
2014-09-05  4:13             ` 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).