* [PATCH 0/2] Variable tracking and subvalues
@ 2022-09-07 14:20 Stefan Schulze Frielinghaus
2022-09-07 14:20 ` [PATCH 1/2] cselib: Keep track of further subvalue relations Stefan Schulze Frielinghaus
2022-09-07 14:20 ` [PATCH 2/2] var-tracking: Add entry values up to max register mode Stefan Schulze Frielinghaus
0 siblings, 2 replies; 8+ messages in thread
From: Stefan Schulze Frielinghaus @ 2022-09-07 14:20 UTC (permalink / raw)
To: gcc-patches
For variable tracking there exists cases where a value is moved in a
wider mode than its native mode. For example:
int
foo (int x)
{
bar (x);
return x;
}
compiles on IBM zSystems into
0x00000000010012b0 <+0>: stmg %r12,%r15,96(%r15)
0x00000000010012b6 <+6>: lgr %r12,%r2
0x00000000010012ba <+10>: lay %r15,-160(%r15)
0x00000000010012c0 <+16>: brasl %r14,0x10012a0 <f1>
0x00000000010012c6 <+22>: lgr %r2,%r12
0x00000000010012ca <+26>: lmg %r12,%r15,256(%r15)
0x00000000010012d0 <+32>: br %r14
Initially variable x with SImode is held in register r2 which is moved
to call-saved register r12 with DImode from where it is also restored.
The cselib patch records that the initial value held in r2 is a subvalue
of r12 which enables var-tracking to emit a register location entry:
(gdb) info address x
Symbol "x" is multi-location:
Base address 0x10012b0 Range 0x10012b0-0x10012c5: a variable in $r2
Range 0x10012c5-0x10012d0: a variable in $r12
Range 0x10012d0-0x10012d2: a variable in $r2
However, this only works for straight-line programs and fails e.g. for
__attribute__((noinline, noclone)) void
fn1 (int x)
{
__asm volatile ("" : "+r" (x) : : "memory");
}
__attribute__((noinline, noclone)) int
fn2 (int x, int y)
{
if (x)
{
fn1 (x); // (*)
fn1 (x);
}
return y;
}
__attribute__((noinline, noclone)) int
fn3 (int x, int y)
{
return fn2 (x, y);
}
int
main ()
{
fn3 (36, 25);
return 0;
}
At (*) variable x is moved into a call-saved register. However, the
former cselib patch does not cover this since cselib flushes its tables
across jumps. In order to not give up entirely by the second patch an
entry value is referred.
In summary this fixes the following guality tests for IBM zSystems:
Fixed by cselib patch:
FAIL: gcc.dg/guality/pr43051-1.c -O1 -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects -DPREVENT_OPTIMIZATION line 40 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O2 -DPREVENT_OPTIMIZATION line 40 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 40 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O3 -g -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O3 -g -DPREVENT_OPTIMIZATION line 40 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O2 -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions -DPREVENT_OPTIMIZATION line 40 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -Og -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -Og -DPREVENT_OPTIMIZATION line 40 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -O1 -DPREVENT_OPTIMIZATION line 40 v == 1
Fixed by var-tracking patch:
FAIL: gcc.dg/guality/pr54519-1.c -O2 -DPREVENT_OPTIMIZATION line 23 x == 98
FAIL: gcc.dg/guality/pr54519-5.c -Og -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 20 x == 36
FAIL: gcc.dg/guality/pr54519-1.c -Og -DPREVENT_OPTIMIZATION line 20 x == 36
FAIL: gcc.dg/guality/pr54519-1.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 23 x == 98
FAIL: gcc.dg/guality/pr54551.c -O2 -flto -fno-use-linker-plugin -flto-partition=none -DPREVENT_OPTIMIZATION line 18 a == 4
FAIL: gcc.dg/guality/pr54551.c -O3 -g -DPREVENT_OPTIMIZATION line 18 a == 4
FAIL: gcc.dg/guality/pr54519-1.c -O1 -DPREVENT_OPTIMIZATION line 23 x == 98
FAIL: gcc.dg/guality/pr54551.c -Os -DPREVENT_OPTIMIZATION line 18 a == 4
FAIL: gcc.dg/guality/pr54519-5.c -O1 -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-1.c -O1 -DPREVENT_OPTIMIZATION line 20 x == 36
FAIL: gcc.dg/guality/pr54519-4.c -Os -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-3.c -O3 -g -DPREVENT_OPTIMIZATION line 23 z == 8
FAIL: gcc.dg/guality/pr54551.c -O2 -DPREVENT_OPTIMIZATION line 18 a == 4
FAIL: gcc.dg/guality/pr54551.c -O1 -DPREVENT_OPTIMIZATION line 18 a == 4
FAIL: gcc.dg/guality/pr54519-1.c -O2 -DPREVENT_OPTIMIZATION line 20 x == 36
FAIL: gcc.dg/guality/pr54693-2.c -Os -DPREVENT_OPTIMIZATION line 21 x == 10 - i
FAIL: gcc.dg/guality/pr54519-5.c -O2 -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-3.c -Os -DPREVENT_OPTIMIZATION line 20 z == 6
FAIL: gcc.dg/guality/pr54519-1.c -Og -DPREVENT_OPTIMIZATION line 23 x == 98
FAIL: gcc.dg/guality/pr54519-3.c -O2 -DPREVENT_OPTIMIZATION line 20 z == 6
FAIL: gcc.dg/guality/pr54551.c -Og -DPREVENT_OPTIMIZATION line 18 a == 4
FAIL: gcc.dg/guality/pr54519-3.c -O2 -DPREVENT_OPTIMIZATION line 23 z == 8
FAIL: gcc.dg/guality/pr54519-4.c -O2 -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-5.c -Os -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54693-2.c -O1 -DPREVENT_OPTIMIZATION line 21 y == 20 - 2 * i
FAIL: gcc.dg/guality/pr54519-4.c -O3 -g -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-5.c -O3 -g -DPREVENT_OPTIMIZATION line 17 y == 25
FAIL: gcc.dg/guality/pr54519-3.c -O3 -g -DPREVENT_OPTIMIZATION line 20 z == 6
FAIL: gcc.dg/guality/pr54519-3.c -Os -DPREVENT_OPTIMIZATION line 23 z == 8
FAIL: gcc.dg/guality/pr54693-2.c -O1 -DPREVENT_OPTIMIZATION line 21 x == 10 - i
FAIL: gcc.dg/guality/pr54693-2.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions -DPREVENT_OPTIMIZATION line 21 y == 20 - 2 * i
Fixed by cselib as well as var-tracking patches:
FAIL: gcc.dg/guality/pr54519-1.c -Os -DPREVENT_OPTIMIZATION line 23 x == 98
FAIL: gcc.dg/guality/pr54519-1.c -Og -DPREVENT_OPTIMIZATION line 20 y == 25
FAIL: gcc.dg/guality/pr54519-1.c -O1 -DPREVENT_OPTIMIZATION line 20 y == 25
FAIL: gcc.dg/guality/pr54519-2.c -O1 -DPREVENT_OPTIMIZATION line 17 x == 6
FAIL: gcc.dg/guality/pr54519-5.c -O1 -DPREVENT_OPTIMIZATION line 17 x == 6
FAIL: gcc.dg/guality/pr54519-5.c -Og -DPREVENT_OPTIMIZATION line 17 x == 6
FAIL: gcc.dg/guality/pr54519-1.c -Os -DPREVENT_OPTIMIZATION line 20 x == 36
FAIL: gcc.dg/guality/pr54519-2.c -Og -DPREVENT_OPTIMIZATION line 17 x == 6
FAIL: gcc.dg/guality/pr54519-1.c -O1 -DPREVENT_OPTIMIZATION line 23 y == 117
FAIL: gcc.dg/guality/pr54519-1.c -Og -DPREVENT_OPTIMIZATION line 23 y == 117
Fixed only in conjunction of both patches:
FAIL: gcc.dg/guality/pr43051-1.c -Os -DPREVENT_OPTIMIZATION line 35 v == 1
FAIL: gcc.dg/guality/pr43051-1.c -Os -DPREVENT_OPTIMIZATION line 40 v == 1
Bootstrapped and regtested on IBM zSystem as well as x86_64. Ok for
mainline?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] cselib: Keep track of further subvalue relations
2022-09-07 14:20 [PATCH 0/2] Variable tracking and subvalues Stefan Schulze Frielinghaus
@ 2022-09-07 14:20 ` Stefan Schulze Frielinghaus
2022-09-26 6:10 ` Stefan Schulze Frielinghaus
2022-09-27 23:46 ` Jeff Law
2022-09-07 14:20 ` [PATCH 2/2] var-tracking: Add entry values up to max register mode Stefan Schulze Frielinghaus
1 sibling, 2 replies; 8+ messages in thread
From: Stefan Schulze Frielinghaus @ 2022-09-07 14:20 UTC (permalink / raw)
To: gcc-patches; +Cc: Stefan Schulze Frielinghaus
Whenever a new cselib value is created check whether a smaller value
exists which is contained in the bigger one. If so add a subreg
relation to locs of the smaller one.
gcc/ChangeLog:
* cselib.cc (new_cselib_val): Keep track of further subvalue
relations.
---
gcc/cselib.cc | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/gcc/cselib.cc b/gcc/cselib.cc
index 6a5609786fa..9b582e5d3d6 100644
--- a/gcc/cselib.cc
+++ b/gcc/cselib.cc
@@ -1569,6 +1569,26 @@ new_cselib_val (unsigned int hash, machine_mode mode, rtx x)
e->locs = 0;
e->next_containing_mem = 0;
+ scalar_int_mode int_mode;
+ if (REG_P (x) && is_int_mode (mode, &int_mode)
+ && REG_VALUES (REGNO (x)) != NULL
+ && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
+ {
+ rtx copy = shallow_copy_rtx (x);
+ scalar_int_mode narrow_mode_iter;
+ FOR_EACH_MODE_UNTIL (narrow_mode_iter, int_mode)
+ {
+ PUT_MODE_RAW (copy, narrow_mode_iter);
+ cselib_val *v = cselib_lookup (copy, narrow_mode_iter, 0, VOIDmode);
+ if (v)
+ {
+ rtx sub = lowpart_subreg (narrow_mode_iter, e->val_rtx, int_mode);
+ if (sub)
+ new_elt_loc_list (v, sub);
+ }
+ }
+ }
+
if (dump_file && (dump_flags & TDF_CSELIB))
{
fprintf (dump_file, "cselib value %u:%u ", e->uid, hash);
--
2.37.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] var-tracking: Add entry values up to max register mode
2022-09-07 14:20 [PATCH 0/2] Variable tracking and subvalues Stefan Schulze Frielinghaus
2022-09-07 14:20 ` [PATCH 1/2] cselib: Keep track of further subvalue relations Stefan Schulze Frielinghaus
@ 2022-09-07 14:20 ` Stefan Schulze Frielinghaus
2022-09-26 6:10 ` Stefan Schulze Frielinghaus
2022-09-27 23:44 ` Jeff Law
1 sibling, 2 replies; 8+ messages in thread
From: Stefan Schulze Frielinghaus @ 2022-09-07 14:20 UTC (permalink / raw)
To: gcc-patches; +Cc: Stefan Schulze Frielinghaus
For parameter of type integer which do not consume a whole register
(modulo sign/zero extension) this patch adds entry values up to maximal
register mode.
gcc/ChangeLog:
* var-tracking.cc (vt_add_function_parameter): Add entry values
up to maximal register mode.
---
gcc/var-tracking.cc | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/gcc/var-tracking.cc b/gcc/var-tracking.cc
index 235981d100f..9c40ec4fb8b 100644
--- a/gcc/var-tracking.cc
+++ b/gcc/var-tracking.cc
@@ -9906,6 +9906,23 @@ vt_add_function_parameter (tree parm)
VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
}
}
+
+ if (GET_MODE_CLASS (mode) == MODE_INT)
+ {
+ machine_mode wider_mode_iter;
+ FOR_EACH_WIDER_MODE (wider_mode_iter, mode)
+ {
+ if (!HWI_COMPUTABLE_MODE_P (wider_mode_iter))
+ break;
+ rtx wider_reg
+ = gen_rtx_REG (wider_mode_iter, REGNO (incoming));
+ cselib_val *wider_val
+ = cselib_lookup_from_insn (wider_reg, wider_mode_iter, 1,
+ VOIDmode, get_insns ());
+ preserve_value (wider_val);
+ record_entry_value (wider_val, wider_reg);
+ }
+ }
}
}
else if (GET_CODE (incoming) == PARALLEL && !dv_onepart_p (dv))
--
2.37.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] cselib: Keep track of further subvalue relations
2022-09-07 14:20 ` [PATCH 1/2] cselib: Keep track of further subvalue relations Stefan Schulze Frielinghaus
@ 2022-09-26 6:10 ` Stefan Schulze Frielinghaus
2022-09-27 23:46 ` Jeff Law
1 sibling, 0 replies; 8+ messages in thread
From: Stefan Schulze Frielinghaus @ 2022-09-26 6:10 UTC (permalink / raw)
To: gcc-patches
Ping.
On Wed, Sep 07, 2022 at 04:20:25PM +0200, Stefan Schulze Frielinghaus wrote:
> Whenever a new cselib value is created check whether a smaller value
> exists which is contained in the bigger one. If so add a subreg
> relation to locs of the smaller one.
>
> gcc/ChangeLog:
>
> * cselib.cc (new_cselib_val): Keep track of further subvalue
> relations.
> ---
> gcc/cselib.cc | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/gcc/cselib.cc b/gcc/cselib.cc
> index 6a5609786fa..9b582e5d3d6 100644
> --- a/gcc/cselib.cc
> +++ b/gcc/cselib.cc
> @@ -1569,6 +1569,26 @@ new_cselib_val (unsigned int hash, machine_mode mode, rtx x)
> e->locs = 0;
> e->next_containing_mem = 0;
>
> + scalar_int_mode int_mode;
> + if (REG_P (x) && is_int_mode (mode, &int_mode)
> + && REG_VALUES (REGNO (x)) != NULL
> + && (!cselib_current_insn || !DEBUG_INSN_P (cselib_current_insn)))
> + {
> + rtx copy = shallow_copy_rtx (x);
> + scalar_int_mode narrow_mode_iter;
> + FOR_EACH_MODE_UNTIL (narrow_mode_iter, int_mode)
> + {
> + PUT_MODE_RAW (copy, narrow_mode_iter);
> + cselib_val *v = cselib_lookup (copy, narrow_mode_iter, 0, VOIDmode);
> + if (v)
> + {
> + rtx sub = lowpart_subreg (narrow_mode_iter, e->val_rtx, int_mode);
> + if (sub)
> + new_elt_loc_list (v, sub);
> + }
> + }
> + }
> +
> if (dump_file && (dump_flags & TDF_CSELIB))
> {
> fprintf (dump_file, "cselib value %u:%u ", e->uid, hash);
> --
> 2.37.2
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] var-tracking: Add entry values up to max register mode
2022-09-07 14:20 ` [PATCH 2/2] var-tracking: Add entry values up to max register mode Stefan Schulze Frielinghaus
@ 2022-09-26 6:10 ` Stefan Schulze Frielinghaus
2022-09-27 23:44 ` Jeff Law
1 sibling, 0 replies; 8+ messages in thread
From: Stefan Schulze Frielinghaus @ 2022-09-26 6:10 UTC (permalink / raw)
To: gcc-patches
Ping.
On Wed, Sep 07, 2022 at 04:20:26PM +0200, Stefan Schulze Frielinghaus wrote:
> For parameter of type integer which do not consume a whole register
> (modulo sign/zero extension) this patch adds entry values up to maximal
> register mode.
>
> gcc/ChangeLog:
>
> * var-tracking.cc (vt_add_function_parameter): Add entry values
> up to maximal register mode.
> ---
> gcc/var-tracking.cc | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/gcc/var-tracking.cc b/gcc/var-tracking.cc
> index 235981d100f..9c40ec4fb8b 100644
> --- a/gcc/var-tracking.cc
> +++ b/gcc/var-tracking.cc
> @@ -9906,6 +9906,23 @@ vt_add_function_parameter (tree parm)
> VAR_INIT_STATUS_INITIALIZED, NULL, INSERT);
> }
> }
> +
> + if (GET_MODE_CLASS (mode) == MODE_INT)
> + {
> + machine_mode wider_mode_iter;
> + FOR_EACH_WIDER_MODE (wider_mode_iter, mode)
> + {
> + if (!HWI_COMPUTABLE_MODE_P (wider_mode_iter))
> + break;
> + rtx wider_reg
> + = gen_rtx_REG (wider_mode_iter, REGNO (incoming));
> + cselib_val *wider_val
> + = cselib_lookup_from_insn (wider_reg, wider_mode_iter, 1,
> + VOIDmode, get_insns ());
> + preserve_value (wider_val);
> + record_entry_value (wider_val, wider_reg);
> + }
> + }
> }
> }
> else if (GET_CODE (incoming) == PARALLEL && !dv_onepart_p (dv))
> --
> 2.37.2
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] var-tracking: Add entry values up to max register mode
2022-09-07 14:20 ` [PATCH 2/2] var-tracking: Add entry values up to max register mode Stefan Schulze Frielinghaus
2022-09-26 6:10 ` Stefan Schulze Frielinghaus
@ 2022-09-27 23:44 ` Jeff Law
1 sibling, 0 replies; 8+ messages in thread
From: Jeff Law @ 2022-09-27 23:44 UTC (permalink / raw)
To: gcc-patches
On 9/7/22 08:20, Stefan Schulze Frielinghaus via Gcc-patches wrote:
> For parameter of type integer which do not consume a whole register
> (modulo sign/zero extension) this patch adds entry values up to maximal
> register mode.
>
> gcc/ChangeLog:
>
> * var-tracking.cc (vt_add_function_parameter): Add entry values
> up to maximal register mode.
OK
jeff
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] cselib: Keep track of further subvalue relations
2022-09-07 14:20 ` [PATCH 1/2] cselib: Keep track of further subvalue relations Stefan Schulze Frielinghaus
2022-09-26 6:10 ` Stefan Schulze Frielinghaus
@ 2022-09-27 23:46 ` Jeff Law
2022-09-29 17:40 ` Joseph Myers
1 sibling, 1 reply; 8+ messages in thread
From: Jeff Law @ 2022-09-27 23:46 UTC (permalink / raw)
To: gcc-patches
On 9/7/22 08:20, Stefan Schulze Frielinghaus via Gcc-patches wrote:
> Whenever a new cselib value is created check whether a smaller value
> exists which is contained in the bigger one. If so add a subreg
> relation to locs of the smaller one.
>
> gcc/ChangeLog:
>
> * cselib.cc (new_cselib_val): Keep track of further subvalue
> relations.
OK
jeff
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] cselib: Keep track of further subvalue relations
2022-09-27 23:46 ` Jeff Law
@ 2022-09-29 17:40 ` Joseph Myers
0 siblings, 0 replies; 8+ messages in thread
From: Joseph Myers @ 2022-09-29 17:40 UTC (permalink / raw)
To: Jeff Law, Stefan Schulze Frielinghaus; +Cc: gcc-patches
This introduces an ICE building libgcc for ia64-linux-gnu.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107088
https://sourceware.org/pipermail/libc-testresults/2022q3/010294.html
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-09-29 17:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 14:20 [PATCH 0/2] Variable tracking and subvalues Stefan Schulze Frielinghaus
2022-09-07 14:20 ` [PATCH 1/2] cselib: Keep track of further subvalue relations Stefan Schulze Frielinghaus
2022-09-26 6:10 ` Stefan Schulze Frielinghaus
2022-09-27 23:46 ` Jeff Law
2022-09-29 17:40 ` Joseph Myers
2022-09-07 14:20 ` [PATCH 2/2] var-tracking: Add entry values up to max register mode Stefan Schulze Frielinghaus
2022-09-26 6:10 ` Stefan Schulze Frielinghaus
2022-09-27 23:44 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).