This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[RFC] Confusing fall through BB pc in conditional jump
- From: "Kewen.Lin" <linkw at linux dot ibm dot com>
- To: GCC Development <gcc at gcc dot gnu dot org>
- Cc: Bill Schmidt <wschmidt at linux dot ibm dot com>, Segher Boessenkool <segher at kernel dot crashing dot org>
- Date: Thu, 27 Jun 2019 10:32:18 +0800
- Subject: [RFC] Confusing fall through BB pc in conditional jump
Hi all,
6: NOTE_INSN_BASIC_BLOCK 2
....
12: r135:CC=cmp(r122:DI,0)
13: pc={(r135:CC!=0)?L52:pc}
REG_DEAD r135:CC
REG_BR_PROB 1041558836
31: L31:
17: NOTE_INSN_BASIC_BLOCK 3
The above RTL seq is from pass doloop dumping with -fdump-rtl-all-slim, I misunderstood that:
the fall through BB of BB 2 is BB 3, since BB 3 is placed just next to BB 2.
Then I found the contradiction that BB 3 will have some uninitialized regs if it's true.
I can get the exact information with "-blocks" dumping and even detailed one with "-details".
But I'm thinking whether it's worth to giving some information on "-slim" dump (or more
exactly without "-blocks") to avoid some confusion especially for new comers like me.
Or is it unnecessary? since we have "-blocks" options for that and want to keep it "slim"?
Any comments on that?
Thanks in advance!
-------------------------------
The below patch is to append the hint on pc target when we find jump insn with if-then-else
and the target BB with known code label.
The dumping will look like:
6: NOTE_INSN_BASIC_BLOCK 2
...
12: r135:CC=cmp(r122:DI,0)
13: pc={(r135:CC!=0)?L52:pc}
REG_DEAD r135:CC
REG_BR_PROB 1041558836
;; pc (fall through) -> L67
31: L31:
17: NOTE_INSN_BASIC_BLOCK 3
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index a1ca5992c41..608bcd130c5 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -2164,7 +2164,27 @@ rtl_dump_bb (FILE *outf, basic_block bb, int indent, dump_flags_t flags)
}
}
-^L
+
+/* For dumping without specifying basic blocks option, when we see pc is one of
+ jump targets, it's easy to misunderstand the next basic block is the
+ fallthrough one, but it's not so true. This function is to dump some hints
+ for that. */
+
+static void
+dump_hints_for_jump_target_pc (FILE *outf, basic_block bb)
+{
+ gcc_assert (outf);
+ edge e = FALLTHRU_EDGE (bb);
+ basic_block dest = e->dest;
+ rtx_insn *label = BB_HEAD (dest);
+ if (!LABEL_P (label))
+ return;
+
+ fputs (";; ", outf);
+ fprintf (outf, " pc (fall through) -> L%d", INSN_UID (label));
+ fputc ('\n', outf);
+}
+
/* Like dump_function_to_file, but for RTL. Print out dataflow information
for the start of each basic block. FLAGS are the TDF_* masks documented
in dumpfile.h. */
@@ -2255,6 +2275,14 @@ print_rtl_with_bb (FILE *outf, const rtx_insn *rtx_first, dump_flags_t flags)
putc ('\n', outf);
}
}
+ else if (GET_CODE (tmp_rtx) == JUMP_INSN
+ && GET_CODE (PATTERN (tmp_rtx)) == SET)
+ {
+ bb = BLOCK_FOR_INSN (tmp_rtx);
+ const_rtx src = SET_SRC (PATTERN (tmp_rtx));
+ if (bb != NULL && GET_CODE (src) == IF_THEN_ELSE)
+ dump_hints_for_jump_target_pc (outf, bb);
+ }
}
free (start);