From dbedefae43f712ee9f0636585bb1f91793c088d0 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Sat, 18 Dec 2004 14:38:44 +0000 Subject: [PATCH] re PR middle-end/18548 (Miscompiles code generated by Gambit-C Scheme->C compiler) PR middle-end/18548 * expr.c (expand_expr_real_1) : Ensure that target, op0 and op1 are all registers (or constants) before expanding the RTL comparison sequence [to avoid reg_overlap_mentioned (target, op1)]. * gcc.dg/max-1.c: New test case. From-SVN: r92351 --- gcc/ChangeLog | 7 +++++++ gcc/expr.c | 7 ++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/max-1.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/max-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a98a1d7d83b..024e48bbcef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2004-12-18 Roger Sayle + + PR middle-end/18548 + * expr.c (expand_expr_real_1) : Ensure that target, op0 + and op1 are all registers (or constants) before expanding the RTL + comparison sequence [to avoid reg_overlap_mentioned (target, op1)]. + 2004-12-18 Eric Botcazou PR rtl-optimization/16968 diff --git a/gcc/expr.c b/gcc/expr.c index fffb60d003b..2581c150dba 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7671,7 +7671,7 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, /* At this point, a MEM target is no longer useful; we will get better code without it. */ - if (MEM_P (target)) + if (! REG_P (target)) target = gen_reg_rtx (mode); /* If op1 was placed in target, swap op0 and op1. */ @@ -7682,6 +7682,11 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, op1 = tem; } + /* We generate better code and avoid problems with op1 mentioning + target by forcing op1 into a pseudo if it isn't a constant. */ + if (! CONSTANT_P (op1)) + op1 = force_reg (mode, op1); + if (target != op0) emit_move_insn (target, op0); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1ef26bacd31..5380e992ee3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-12-18 Roger Sayle + + PR middle-end/18548 + * gcc.dg/max-1.c: New test case. + 2004-12-18 Jakub Jelinek * gcc.c-torture/execute/20041218-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/max-1.c b/gcc/testsuite/gcc.dg/max-1.c new file mode 100644 index 00000000000..7f03edc590d --- /dev/null +++ b/gcc/testsuite/gcc.dg/max-1.c @@ -0,0 +1,33 @@ +/* PR middle-end/18548 */ +/* Test case reduced by Andrew Pinski */ +/* { dg-do run } */ +/* { dg-options "-O1 -fno-tree-lrs" } */ + +extern void abort (void); + +long fff[10]; + +void f(long a, long b) +{ + long crcc = b; + long d = *((long*)(a+1)); + int i; + + a = d >= b? d:b; + + + for(i=0;i<10;i++) + fff[i] = a; +} + +int main(void) +{ + int i; + long a = 10; + f((long)(&a)-1,0); + for(i = 0;i<10;i++) + if (fff[i]!=10) + abort (); + return 0; +} +