diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/loop-invariant.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr103837.c | 19 |
2 files changed, 34 insertions, 4 deletions
diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 5eee2e5..be95155 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -1691,6 +1691,7 @@ can_move_invariant_reg (class loop *loop, struct invariant *inv, rtx reg) unsigned int dest_regno, defs_in_loop_count = 0; rtx_insn *insn = inv->insn; basic_block bb = BLOCK_FOR_INSN (inv->insn); + auto_vec <rtx_insn *, 16> debug_insns_to_reset; /* We ignore hard register and memory access for cost and complexity reasons. Hard register are few at this stage and expensive to consider as they @@ -1725,10 +1726,13 @@ can_move_invariant_reg (class loop *loop, struct invariant *inv, rtx reg) continue; /* Don't move if a use is not dominated by def in insn. */ - if (use_bb == bb && DF_INSN_LUID (insn) >= DF_INSN_LUID (use_insn)) - return false; - if (!dominated_by_p (CDI_DOMINATORS, use_bb, bb)) - return false; + if ((use_bb == bb && DF_INSN_LUID (insn) >= DF_INSN_LUID (use_insn)) + || !dominated_by_p (CDI_DOMINATORS, use_bb, bb)) + { + if (!DEBUG_INSN_P (use_insn)) + return false; + debug_insns_to_reset.safe_push (use_insn); + } } /* Check for other defs. Any other def in the loop might reach a use @@ -1751,6 +1755,13 @@ can_move_invariant_reg (class loop *loop, struct invariant *inv, rtx reg) return false; } + /* Reset debug uses if a use is not dominated by def in insn. */ + for (auto use_insn : debug_insns_to_reset) + { + INSN_VAR_LOCATION_LOC (use_insn) = gen_rtx_UNKNOWN_VAR_LOC (); + df_insn_rescan (use_insn); + } + return true; } diff --git a/gcc/testsuite/gcc.dg/pr103837.c b/gcc/testsuite/gcc.dg/pr103837.c new file mode 100644 index 0000000..43593d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103837.c @@ -0,0 +1,19 @@ +/* PR rtl-optimization/103837 */ +/* { dg-do compile } */ +/* { dg-options "-Og -fcompare-debug -fmove-loop-invariants -fnon-call-exceptions -fexceptions -fdelete-dead-exceptions -fno-tree-dce -w" } */ + +unsigned long int +foo (int x) +{ + double a; + int b; + unsigned long int ret = a; + + for (;;) + { + b = !!((int) a); + a = x; + } + + return ret; +} |