public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 0/2] Variable tracking and subvalues
Date: Wed,  7 Sep 2022 16:20:24 +0200	[thread overview]
Message-ID: <20220907142026.936922-1-stefansf@linux.ibm.com> (raw)

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?



             reply	other threads:[~2022-09-07 14:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-07 14:20 Stefan Schulze Frielinghaus [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220907142026.936922-1-stefansf@linux.ibm.com \
    --to=stefansf@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).