diff mbox series

Update crtl->has_bb_partition if NOTE_INSN_SWITCH_SECTIONS isn't emitted (PR debug/83585)

Message ID 20180103205425.GN1833@tucnak
State New
Headers show
Series Update crtl->has_bb_partition if NOTE_INSN_SWITCH_SECTIONS isn't emitted (PR debug/83585) | expand

Commit Message

Jakub Jelinek Jan. 3, 2018, 8:54 p.m. UTC
Hi!

My recent dwarf2out.c, dbxout.c and rs6000.c uses of crtl->has_bb_partition
all assume that if it is true then the function actually has 2 partitions
and NOTE_INSN_SWITCH_SECTIONS is present, but as the following testcase
shows, that isn't always the case, crtl->has_bb_partition is set during
bbpart pass if there are 2 partitions, but there are many passes in between
and all bbs of one of the partitions could be optimized away.

Are there any uses of this flag that would be interested in whether the
function had any partitions in the past (I guess that also means
BB_PARTITION is not unspecified), rather than whether the function has 2
partitions right now?  If yes, instead of this patch we could introduce
a new flag in cfun set by insert_section_boundary_note.  If not, the
following patch should be sufficient.

Bootstrapped/regtested on x86_64-linux and i686-linux.

2018-01-03  Jakub Jelinek  <jakub@redhat.com>

	PR debug/83585
	* bb-reorder.c (insert_section_boundary_note): Set has_bb_partition
	to switched_sections.

	* gcc.dg/pr83585.c: New test.


	Jakub

Comments

Jeff Law Jan. 4, 2018, 5:44 p.m. UTC | #1
On 01/03/2018 01:54 PM, Jakub Jelinek wrote:
> Hi!
> 
> My recent dwarf2out.c, dbxout.c and rs6000.c uses of crtl->has_bb_partition
> all assume that if it is true then the function actually has 2 partitions
> and NOTE_INSN_SWITCH_SECTIONS is present, but as the following testcase
> shows, that isn't always the case, crtl->has_bb_partition is set during
> bbpart pass if there are 2 partitions, but there are many passes in between
> and all bbs of one of the partitions could be optimized away.
> 
> Are there any uses of this flag that would be interested in whether the
> function had any partitions in the past (I guess that also means
> BB_PARTITION is not unspecified), rather than whether the function has 2
> partitions right now?  If yes, instead of this patch we could introduce
> a new flag in cfun set by insert_section_boundary_note.  If not, the
> following patch should be sufficient.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux.
> 
> 2018-01-03  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR debug/83585
> 	* bb-reorder.c (insert_section_boundary_note): Set has_bb_partition
> 	to switched_sections.
> 
> 	* gcc.dg/pr83585.c: New test.
I don't think the question of whether or not there were partitions in
the past is particularly interesting -- I could probably conjure up a
need, but it wouldn't be based on any actual need I'm aware of.

Let's go with this until such time as a port really needs to answer that
kind of question.

jeff
diff mbox series

Patch

--- gcc/bb-reorder.c.jj	2018-01-03 10:19:55.303533981 +0100
+++ gcc/bb-reorder.c	2018-01-03 18:16:32.470555769 +0100
@@ -2523,6 +2523,11 @@  insert_section_boundary_note (void)
           current_partition = BB_PARTITION (bb);
 	}
     }
+
+  /* Make sure crtl->has_bb_partition matches reality even if bbpart finds
+     some hot and some cold basic blocks, but later one of those kinds is
+     optimized away.  */
+  crtl->has_bb_partition = switched_sections;
 }
 
 namespace {
--- gcc/testsuite/gcc.dg/pr83585.c.jj	2018-01-03 18:20:33.685641817 +0100
+++ gcc/testsuite/gcc.dg/pr83585.c	2018-01-03 18:19:29.922619064 +0100
@@ -0,0 +1,18 @@ 
+/* PR debug/83585 */
+/* { dg-do assemble } */
+/* { dg-options "-std=gnu89 -O2 -g -fno-tree-dce -fno-guess-branch-probability" } */
+
+int
+foo (int x)
+{
+  int a, b;
+  for (a = 0; a < 2; ++a)
+    if (x != 0)
+      {
+        for (b = 0; b < 2; ++b)
+          ;
+        return 0;
+      }
+
+  return;
+}