Go to file
Jakub Jelinek e75a0a0358 dwarf2cfi: Improve cfa_reg comparisons [PR103619]
On Tue, Dec 14, 2021 at 10:32:21AM -0700, Jeff Law wrote:
> I think the attached testcase should trigger on c6x with -mbig-endian -O2 -g

Thanks.  Finally I see what's going on.  c6x doesn't really need the CFA
with span > 1 (and I bet neither does armbe), the only reason why
dwf_cfa_reg is called is that the code in 13 cases just tries to compare
the CFA against dwf_cfa_reg (some_reg).  And that dwf_cfa_reg on some reg
that usually isn't a CFA reg results in targetm.dwarf_register_span hook
call, which on targets like c6x or armeb and others for some registers
creates a PARALLEL with various REGs in it, then the loop with the assertion
and finally operator== which just notes that the reg is different and fails.

This seems compile time memory and time inefficient.

The following so far untested patch instead adds an extra operator== and !=
for comparison of cfa_reg with rtx, which has the most common case where it
is a different register number done early without actually invoking
dwf_cfa_reg.  This means the assertion in dwf_cfa_reg can stay as is (at
least until some big endian target needs to have hard frame pointer or stack
pointer with span > 1 as well).
I've removed a different assertion there because it is redundant - dwf_regno
already has exactly that assertion in it too.

And I've included those 2 tweaks to avoid creating a REG in GC memory when
we can use {stack,hard_frame}_pointer_rtx which is already initialized to
the same REG we need by init_emit_regs.

On Tue, Dec 14, 2021 at 03:05:37PM -0700, Jeff Law wrote:
> So if someone is unfamiliar with the underlying issues here and needs to
> twiddle dwarf2cfi, how are they supposed to know if they should compare
> directly or use dwf_cfa_reg?

Comparison without dwf_cfa_reg should be used whenever possible, because
for registers which are never CFA related that won't call
targetm.dwarf_register_span uselessly.

The only comparisons with dwf_cfa_reg I've kept are the:
            regno = dwf_cfa_reg (XEXP (XEXP (dest, 0), 0));

            if (cur_cfa->reg == regno)
              offset -= cur_cfa->offset;
            else if (cur_trace->cfa_store.reg == regno)
              offset -= cur_trace->cfa_store.offset;
            else
              {
                gcc_assert (cur_trace->cfa_temp.reg == regno);
                offset -= cur_trace->cfa_temp.offset;
              }
and
            struct cfa_reg regno = dwf_cfa_reg (XEXP (dest, 0));

            if (cur_cfa->reg == regno)
              offset = -cur_cfa->offset;
            else if (cur_trace->cfa_store.reg == regno)
              offset = -cur_trace->cfa_store.offset;
            else
              {
                gcc_assert (cur_trace->cfa_temp.reg == regno);
                offset = -cur_trace->cfa_temp.offset;
              }
and there are 2 reasons for it:
1) there is an assertion, which guarantees it must compare equal to one of
those 3 cfa related struct cfa_reg structs, so it must be some CFA related
register (so, right now, targetm.dwarf_register_span shouldn't return
non-NULL in those on anything but gcn)
2) it is compared 3 times in a row, so for the GCN case doing
            if (cur_cfa->reg == XEXP (XEXP (dest, 0), 0))
              offset -= cur_cfa->offset;
            else if (cur_trace->cfa_store.reg == XEXP (XEXP (dest, 0), 0))
              offset -= cur_trace->cfa_store.offset;
            else
              {
                gcc_assert (cur_trace->cfa_temp.reg == XEXP (XEXP (dest, 0), 0));
                offset -= cur_trace->cfa_temp.offset;
              }
could actually create more GC allocated garbage than the way it is written
now.  But doing it that way would work fine.

I think for most of the comparisons even comparing with dwf_cfa_reg would
work but be less compile time/memory efficient (e.g. those assertions that
it is equal to some CFA related cfa_reg or in any spots where only the CFA
related regs may appear in the frame related patterns).

I'm aware just of a single spot where comparison with dwf_cfa_reg doesn't
work (when the assert is in dwf_cfa_reg), that is the spot that was ICEing
on your testcase, where we save arbitrary call saved register:
      if (REG_P (src)
          && REGNO (src) != STACK_POINTER_REGNUM
          && REGNO (src) != HARD_FRAME_POINTER_REGNUM
          && cur_cfa->reg == src)

2021-12-15  Jakub Jelinek  <jakub@redhat.com>

	PR debug/103619
	* dwarf2cfi.c (dwf_cfa_reg): Remove gcc_assert.
	(operator==, operator!=): New overloaded operators.
	(dwarf2out_frame_debug_adjust_cfa, dwarf2out_frame_debug_cfa_offset,
	dwarf2out_frame_debug_expr): Compare vars with cfa_reg type directly
	with REG rtxes rather than with dwf_cfa_reg results on those REGs.
	(create_cie_data): Use stack_pointer_rtx instead of
	gen_rtx_REG (Pmode, STACK_POINTER_REGNUM).
	(execute_dwarf2_frame): Use hard_frame_pointer_rtx instead of
	gen_rtx_REG (Pmode, HARD_FRAME_POINTER_REGNUM).
2021-12-15 10:43:44 +01:00
c++tools Daily bump. 2021-10-27 00:16:33 +00:00
config Daily bump. 2021-12-01 00:17:04 +00:00
contrib Daily bump. 2021-12-07 00:16:23 +00:00
fixincludes Daily bump. 2021-11-24 00:16:29 +00:00
gcc dwarf2cfi: Improve cfa_reg comparisons [PR103619] 2021-12-15 10:43:44 +01:00
gnattools Daily bump. 2021-10-23 00:16:26 +00:00
gotools Daily bump. 2021-09-22 00:16:28 +00:00
include Daily bump. 2021-12-13 00:16:28 +00:00
INSTALL
intl Daily bump. 2021-11-30 00:16:44 +00:00
libada Daily bump. 2021-10-23 00:16:26 +00:00
libatomic Daily bump. 2021-07-22 00:16:46 +00:00
libbacktrace Daily bump. 2021-11-13 00:16:39 +00:00
libcc1 Daily bump. 2021-08-18 00:16:48 +00:00
libcody Daily bump. 2021-11-02 00:16:32 +00:00
libcpp Daily bump. 2021-12-05 00:16:28 +00:00
libdecnumber Daily bump. 2021-10-23 00:16:26 +00:00
libffi Daily bump. 2021-11-16 00:16:31 +00:00
libgcc Daily bump. 2021-12-14 00:16:25 +00:00
libgfortran Daily bump. 2021-12-15 00:16:28 +00:00
libgo runtime: set runtime.GOROOT value at build time 2021-09-21 14:31:10 -07:00
libgomp Daily bump. 2021-12-14 00:16:25 +00:00
libiberty Daily bump. 2021-11-30 00:16:44 +00:00
libitm Daily bump. 2021-11-27 00:16:19 +00:00
libobjc
liboffloadmic Daily bump. 2021-10-20 00:16:43 +00:00
libphobos Daily bump. 2021-12-11 00:16:30 +00:00
libquadmath Daily bump. 2021-06-09 00:16:30 +00:00
libsanitizer Daily bump. 2021-12-07 00:16:23 +00:00
libssp
libstdc++-v3 libstdc++: Poor man's case insensitive comparisons in time_get [PR71557] 2021-12-15 10:25:53 +01:00
libvtv
lto-plugin Daily bump. 2021-12-03 00:17:04 +00:00
maintainer-scripts
zlib
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore Add cscope.out to git ignore. 2021-06-24 16:51:40 +05:30
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2021-12-15 00:16:28 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure Adjust CPP_FOR_BUILD 2021-12-02 15:59:37 -05:00
configure.ac Adjust CPP_FOR_BUILD 2021-12-02 15:59:37 -05:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Add myself to write after approval 2021-12-14 15:59:29 +01:00
Makefile.def d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1) 2021-11-30 16:53:28 +01:00
Makefile.in d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1) 2021-11-30 16:53:28 +01:00
Makefile.tpl d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1) 2021-11-30 16:53:28 +01:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.