Go to file
Jan Hubicka 7828dc0705 Remove allocations which are used only for NULL pointer check and free
Extend tree-ssa-dse to remove memory allocations that are used only
to check that return value is non-NULL and freed.

New -fmalloc-dce flag can be used to control malloc/free removal.  I
ended up copying what -fallocation-dse does so -fmalloc-dce=1 enables
malloc/free removal provided return value is unused otherwise and
-fmalloc-dce=2 allows additional NULL pointer checks which it folds to
non-NULL direction.

I also added compensation for the gcc.dg/analyzer/pr101837.c testcase and
added testcase that std::nothrow variant of operator new is now optimized way.

With the -fmalloc-dce=n I can also add a level which emits runtime check for half
of address space and calloc overflow if it seems useful, but perhaps
incrementally.  Adding size parameter tracking is not that hard (I posted WIP
patch for that).

gcc/ChangeLog:

	PR tree-optimization/117370
	* common.opt: Add -fmalloc-dce.
	* common.opt.urls: Update.
	* doc/invoke.texi: Document it; also add missing -flifetime-dse entry.
	* tree-ssa-dce.cc (is_removable_allocation_p): Break out from
	...
	(mark_stmt_if_obviously_necessary): ... here; also check that
	operator new satisfies gimple_call_from_new_or_delete.
	(checks_return_value_of_removable_allocation_p): New Function.
	(mark_all_reaching_defs_necessary_1): add missing case for
	STRDUP and STRNDUP
	(propagate_necessity): Use is_removable_allocation_p and
	checks_return_value_of_removable_allocation_p.
	(eliminate_unnecessary_stmts): Update conditionals that use
	removed allocation; use is_removable_allocation_p.

gcc/testsuite/ChangeLog:

	* g++.dg/cdce3.C: Disable allocation dce.
	* g++.dg/tree-ssa/pr19476-1.C: Likewise.
	* g++.dg/tree-ssa/pr19476-2.C: Likewise.
	* g++.dg/tree-ssa/pr19476-3.C: Likewise.
	* g++.dg/tree-ssa/pr19476-4.C: Likewise.
	* gcc.dg/analyzer/pr101837.c: Disable malloc dce.
	* gcc.dg/tree-ssa/pr19831-3.c: Update.
	* gfortran.dg/pr68078.f90: Disable malloc DCE.
2024-11-14 17:07:06 +01:00
.forgejo
.github
c++tools
config
contrib Daily bump. 2024-11-09 16:03:14 +00:00
fixincludes
gcc Remove allocations which are used only for NULL pointer check and free 2024-11-14 17:07:06 +01:00
gnattools
gotools
include
INSTALL
libada
libatomic
libbacktrace
libcc1
libcody
libcpp c: Handle C23 floating constant {d,D}{32,64,128} suffixes like {df,dd,dl} 2024-11-13 09:44:20 +01:00
libdecnumber
libffi
libgcc libgcc: Fix COPY_ARG_VAL initializer (PR 117537) 2024-11-14 08:59:28 +00:00
libgfortran
libgm2
libgo
libgomp libgomp.texi: Impl. Status - change TR13 to OpenMP 6.0 + fix routine typo 2024-11-14 16:28:20 +01:00
libgrust
libiberty
libitm
libobjc
libphobos
libquadmath
libsanitizer libsanitizer: Update LOCAL_PATCHES 2024-11-12 21:59:49 +08:00
libssp
libstdc++-v3 libstdc++: Add missing constraint to operator+ for std::move_iterator 2024-11-14 15:39:03 +00:00
libvtv
lto-plugin
maintainer-scripts
zlib
.b4-config
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
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
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
SECURITY.txt
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.