In simplify_loads(), phisrcs are created in find_dominating_parents() and are then supposed to be used in rewrite_load_instruction(). However, it may happen (quite often) that find_dominating_parents() find a dominator for one of the branch, create a phi-source for it, record it's usage and then doesn't find a dominator in one of other parent branches. In this case, the function returns early and the created phisrcs are simply ignored. These phisrcs can't be simplified away as dead instructions because they still have their usage recorded. Fix this by explicitly remove these ignored phisrcs. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- memops.c | 5 +++++ validation/mem2reg/dead-phisrc.c | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 validation/mem2reg/dead-phisrc.c diff --git a/memops.c b/memops.c index 30316391e..df2e4d6c2 100644 --- a/memops.c +++ b/memops.c @@ -134,6 +134,11 @@ static void simplify_loads(struct basic_block *bb) goto next_load; } rewrite_load_instruction(insn, dominators); + } else { // cleanup pending phi-sources + pseudo_t phi; + FOR_EACH_PTR(dominators, phi) { + kill_instruction(phi->def); + } END_FOR_EACH_PTR(phi); } } next_load: diff --git a/validation/mem2reg/dead-phisrc.c b/validation/mem2reg/dead-phisrc.c new file mode 100644 index 000000000..4e4f6a8b4 --- /dev/null +++ b/validation/mem2reg/dead-phisrc.c @@ -0,0 +1,17 @@ +static void foo(void) +{ + extern int *a; + + if (a || *a) + ; + if (a[0] || a[1]) + ; +} + +/* + * check-name: dead-phisrc + * check-command: test-linearize $file + * + * check-output-ignore + * check-output-excludes: phisrc + */ -- 2.16.2 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html