From: Richard Sandiford Date: Mon, 20 Jan 2020 18:28:38 +0000 (+0000) Subject: auto-inc-dec: Don't add incs/decs to bare CLOBBERs [PR93124] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ccb68179642cf7ba5ee05a0d8571a95d0145e3a2;p=gcc.git auto-inc-dec: Don't add incs/decs to bare CLOBBERs [PR93124] In this PR, auto-inc-dec was trying to turn: (set (reg X) (plus (reg X) (const_int N))) (clobber (mem (reg X))) into: (clobber (mem (pre_modify (reg X) ...))) But bare clobber insns are just there to describe dataflow. They're not supposed to generate any code. 2020-01-23 Richard Sandiford gcc/ PR rtl-optimization/93124 * auto-inc-dec.c (merge_in_block): Don't add auto inc/decs to bare USE and CLOBBER insns. gcc/testsuite/ * gcc.dg/torture/pr93124.c: New test. --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 55b23927f76..d16ebbb7c3a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-01-23 Richard Sandiford + + PR rtl-optimization/93124 + * auto-inc-dec.c (merge_in_block): Don't add auto inc/decs to + bare USE and CLOBBER insns. + 2020-01-22 Andrew Pinski * config/arc/arc.c (output_short_suffix): Check insn for nullness. diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c index 268231ecaff..7d0d91403f3 100644 --- a/gcc/auto-inc-dec.c +++ b/gcc/auto-inc-dec.c @@ -1602,9 +1602,15 @@ merge_in_block (int max_reg, basic_block bb) else { insn_is_add_or_inc = false; - mem_insn.insn = insn; - if (find_mem (&PATTERN (insn))) - success_in_block++; + /* We can't use auto inc/dec for bare USEs and CLOBBERs, + since they aren't supposed to generate any code. */ + rtx_code code = GET_CODE (PATTERN (insn)); + if (code != USE && code != CLOBBER) + { + mem_insn.insn = insn; + if (find_mem (&PATTERN (insn))) + success_in_block++; + } } /* If the inc insn was merged with a mem, the inc insn is gone diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eeeb1209d19..d10c6fc8b81 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-01-23 Richard Sandiford + + * gcc.dg/torture/pr93124.c: New test. + 2020-01-22 David Malcolm PR analyzer/93382 diff --git a/gcc/testsuite/gcc.dg/torture/pr93124.c b/gcc/testsuite/gcc.dg/torture/pr93124.c new file mode 100644 index 00000000000..16bc8b54f14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr93124.c @@ -0,0 +1,44 @@ +/* { dg-additional-options "-fno-rerun-cse-after-loop -fno-guess-branch-probability -fno-tree-fre" } */ + +int x; + +void fn2 (); +void fn3 (); +void fn4 (); +void fn5 (); +void fn6 (); + +void +fn1 (void) +{ + int n; + for (n = 0;; ++n) { + { + struct { char a[n]; } s; + fn2 (s); + } + struct { unsigned a[x]; } s; + int i, b; + for (i = 0; i < n; ++i) + ; + fn2 (s); + { + struct { char a[n]; } s; + int i; + for (i = 0; i < n; ++i) + s.a[i] = i; + fn3 (s, s); + } + fn4 (); + { + struct { unsigned a[n]; } s; + fn5 (s); + } + { + struct { char a[b]; } s; + for (; i < n;) + s.a[i] = i; + fn6 (s); + } + } +}