From 8c0e07e3842dd90c09fd3f4b5fe17362c5ab4077 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Mon, 16 Jul 2018 09:18:51 +0000 Subject: [PATCH] [debug] Fix pre_dec handling in vartrack When compiling test-case gcc.target/i386/vartrack-1.c with -O1 -g, register bx is pushed in the prologue and popped in the epilogue: ... (insn/f 26 3 27 2 (set (mem:DI (pre_dec:DI (reg/f:DI 7 sp)) [0 S8 A8]) (reg:DI 3 bx)) "vartrack-1.c":10 61 {*pushdi2_rex64} (expr_list:REG_DEAD (reg:DI 3 bx) (nil))) ... (insn/f 29 28 30 2 (set (reg:DI 3 bx) (mem:DI (post_inc:DI (reg/f:DI 7 sp)) [0 S8 A8])) "vartrack-1.c":15 71 {*popdi1} (expr_list:REG_CFA_ADJUST_CFA (set (reg/f:DI 7 sp) (plus:DI (reg/f:DI 7 sp) (const_int 8 [0x8]))) (nil))) ... However, when we adjust those insns in vartrack to eliminate the pre_dec and post_inc, the frame location for the push is at argp - 24, while the one for the pop is at argp - 16: ... (insn/f 26 3 27 2 (parallel [ (set (mem:DI (plus:DI (reg/f:DI 16 argp) (const_int -24 [0xffffffffffffffe8])) [0 S8 A8]) (reg:DI 3 bx)) (set (reg/f:DI 7 sp) (plus:DI (reg/f:DI 16 argp) (const_int -24 [0xffffffffffffffe8]))) ]) "vartrack-1.c":10 61 {*pushdi2_rex64} (expr_list:REG_DEAD (reg:DI 3 bx) (nil))) ... (insn/f 29 28 30 2 (parallel [ (set (reg:DI 3 bx) (mem:DI (plus:DI (reg/f:DI 16 argp) (const_int -16 [0xfffffffffffffff0])) [0 S8 A8])) (set (reg/f:DI 7 sp) (plus:DI (reg/f:DI 16 argp) (const_int -8 [0xfffffffffffffff8]))) ]) "vartrack-1.c":15 71 {*popdi1} (expr_list:REG_CFA_ADJUST_CFA (set (reg/f:DI 7 sp) (plus:DI (reg/f:DI 7 sp) (const_int 8 [0x8]))) (nil))) ... This patch fixes that by moving the stack_adjust modification after adjust_insn in vt_initialize. Bootstrapped and reg-tested on x86_64. 2018-07-16 Tom de Vries PR debug/86455 * var-tracking.c (vt_initialize): Fix pre_dec handling. * gcc.target/i386/vartrack-1.c: New test. From-SVN: r262687 --- gcc/ChangeLog | 5 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.target/i386/vartrack-1.c | 28 ++++++++++++++++++++++ gcc/var-tracking.c | 5 +++- 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/vartrack-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3e394ae407c..b4743f62da3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-07-16 Tom de Vries + + PR debug/86455 + * var-tracking.c (vt_initialize): Fix pre_dec handling. + 2018-07-16 Ramana Radhakrishnan * config/aarch64/atomics.md (aarch64_store_execlusive): Add diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b943f233ec0..cdbc0b85cc0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-07-16 Tom de Vries + + PR debug/86455 + * gcc.target/i386/vartrack-1.c: New test. + 2018-07-16 Eric Botcazou * gnat.dg/opt73.adb: New test. diff --git a/gcc/testsuite/gcc.target/i386/vartrack-1.c b/gcc/testsuite/gcc.target/i386/vartrack-1.c new file mode 100644 index 00000000000..15514fc0da7 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/vartrack-1.c @@ -0,0 +1,28 @@ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-O1 -g -fdump-rtl-vartrack-details-slim" } */ + +static volatile int vv = 1; + +extern long foo (long x); + +int +main () +{ + long x = vv; + foo (x); + foo (x + 1); + return 0; +} + +/* Before adjust_insn: + 26: [--sp:DI]=bx:DI + 29: bx:DI=[sp:DI++] + + after adjust_insn: + 26: {[argp:DI-0x10]=bx:DI;sp:DI=argp:DI-0x10;} + 29: {bx:DI=[argp:DI-0x10];sp:DI=argp:DI-0x8;} */ + +/* { dg-final { scan-rtl-dump-times {[0-9][0-9]*: \{\[argp:DI-0x10\]=bx:DI;sp:DI=argp:DI-0x10;\}} 1 "vartrack" } } */ + +/* { dg-final { scan-rtl-dump-times {[0-9][0-9]*: \{bx:DI=\[argp:DI-0x10\];sp:DI=argp:DI-0x8;\}} 1 "vartrack" } } */ + diff --git a/gcc/var-tracking.c b/gcc/var-tracking.c index 6c0460b9fe9..5537fa64085 100644 --- a/gcc/var-tracking.c +++ b/gcc/var-tracking.c @@ -10209,12 +10209,15 @@ vt_initialize (void) log_op_type (PATTERN (insn), bb, insn, MO_ADJUST, dump_file); VTI (bb)->mos.safe_push (mo); - VTI (bb)->out.stack_adjust += pre; } } cselib_hook_called = false; adjust_insn (bb, insn); + + if (!frame_pointer_needed && pre) + VTI (bb)->out.stack_adjust += pre; + if (DEBUG_MARKER_INSN_P (insn)) { reemit_marker_as_note (insn); -- 2.30.2