aboutsummaryrefslogtreecommitdiff
path: root/gcc/loop.c
diff options
context:
space:
mode:
authorJim Wilson <wilson@cygnus.com>1998-04-27 18:39:07 +0000
committerJim Wilson <wilson@gcc.gnu.org>1998-04-27 11:39:07 -0700
commit0628fde6079759bf33e27118e027caaa6f034698 (patch)
treec02632e4e26b9afecd0e5bf71185881cc3f4d644 /gcc/loop.c
parenteae97bd90c2f25af25fe2deb8aa01621783866c9 (diff)
downloadgcc-0628fde6079759bf33e27118e027caaa6f034698.zip
gcc-0628fde6079759bf33e27118e027caaa6f034698.tar.gz
gcc-0628fde6079759bf33e27118e027caaa6f034698.tar.bz2
Fix hppa miscompilation bug reported by Manfred Hollstein.
* loop.c (check_dbra_loop): New locals jump, first_compare, and compare_and_branch. Call get_condition to set first_compare. Set compare_and_branch to number of compare/branch instructions. Replace PREV_INSN (PREV_INSN (loop_end)) with first_compare. Replace '2' with compare_and_branch. From-SVN: r19435
Diffstat (limited to 'gcc/loop.c')
-rw-r--r--gcc/loop.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/gcc/loop.c b/gcc/loop.c
index 6b66484..70ecfa8 100644
--- a/gcc/loop.c
+++ b/gcc/loop.c
@@ -6094,14 +6094,28 @@ check_dbra_loop (loop_end, insn_count, loop_start)
rtx comparison;
rtx before_comparison;
rtx p;
+ rtx jump;
+ rtx first_compare;
+ int compare_and_branch;
/* If last insn is a conditional branch, and the insn before tests a
register value, try to optimize it. Otherwise, we can't do anything. */
- comparison = get_condition_for_loop (PREV_INSN (loop_end));
+ jump = PREV_INSN (loop_end);
+ comparison = get_condition_for_loop (jump);
if (comparison == 0)
return 0;
+ /* Try to compute whether the compare/branch at the loop end is one or
+ two instructions. */
+ get_condition (jump, &first_compare);
+ if (first_compare == jump)
+ compare_and_branch = 1;
+ else if (first_compare == prev_nonnote_insn (jump))
+ compare_and_branch = 2;
+ else
+ return 0;
+
/* Check all of the bivs to see if the compare uses one of them.
Skip biv's set more than once because we can't guarantee that
it will be zero on the last iteration. Also skip if the biv is
@@ -6112,7 +6126,7 @@ check_dbra_loop (loop_end, insn_count, loop_start)
if (bl->biv_count == 1
&& bl->biv->dest_reg == XEXP (comparison, 0)
&& ! reg_used_between_p (regno_reg_rtx[bl->regno], bl->biv->insn,
- PREV_INSN (PREV_INSN (loop_end))))
+ first_compare))
break;
}
@@ -6253,7 +6267,7 @@ check_dbra_loop (loop_end, insn_count, loop_start)
&& reversible_mem_store
&& (no_use_except_counting
|| ((bl->giv_count + bl->biv_count + num_mem_sets
- + num_movables + 2 == insn_count)
+ + num_movables + compare_and_branch == insn_count)
&& (bl == loop_iv_list && bl->next == 0))))
{
rtx tem;
@@ -6345,8 +6359,7 @@ check_dbra_loop (loop_end, insn_count, loop_start)
/* Emit an insn after the end of the loop to set the biv's
proper exit value if it is used anywhere outside the loop. */
- if ((REGNO_LAST_UID (bl->regno)
- != INSN_UID (PREV_INSN (PREV_INSN (loop_end))))
+ if ((REGNO_LAST_UID (bl->regno) != INSN_UID (first_compare))
|| ! bl->init_insn
|| REGNO_FIRST_UID (bl->regno) != INSN_UID (bl->init_insn))
emit_insn_after (gen_move_insn (reg, final_value),
@@ -6354,7 +6367,8 @@ check_dbra_loop (loop_end, insn_count, loop_start)
/* Delete compare/branch at end of loop. */
delete_insn (PREV_INSN (loop_end));
- delete_insn (PREV_INSN (loop_end));
+ if (compare_and_branch == 2)
+ delete_insn (first_compare);
/* Add new compare/branch insn at end of loop. */
start_sequence ();