Find a file
Jakub Jelinek 4dda30e991 middle-end IFN_ASSUME support [PR106654]
My earlier patches gimplify the simplest non-side-effects assumptions
into if (cond) ; else __builtin_unreachable (); and throw the rest
on the floor.
The following patch attempts to do something with the rest too.
For -O0, it throws the more complex assumptions on the floor,
we don't expect optimizations and the assumptions are there to allow
optimizations.  Otherwise arranges for the assumptions to be
visible in the IL as
  .ASSUME (_Z2f4i._assume.0, i_1(D));
call where there is an artificial function like:
bool _Z2f4i._assume.0 (int i)
{
  bool _2;

  <bb 2> [local count: 1073741824]:
  _2 = i_1(D) == 43;
  return _2;

}
with the semantics that there is UB unless the assumption function
would return true.

Aldy, could ranger handle this?  If it sees .ASSUME call,
walk the body of such function from the edge(s) to exit with the
assumption that the function returns true, so above set _2 [true, true]
and from there derive that i_1(D) [43, 43] and then map the argument
in the assumption function to argument passed to IFN_ASSUME (note,
args there are shifted by 1)?

During gimplification it actually gimplifies it into
  [[assume (D.2591)]]
    {
      {
        i = i + 1;
        D.2591 = i == 44;
      }
    }
which is a new GIMPLE_ASSUME statement wrapping a GIMPLE_BIND and
specifying a boolean_type_node variable which contains the result.
The GIMPLE_ASSUME then survives just a couple of passes and is lowered
during gimple lowering into an outlined separate function and
IFN_ASSUME call.  Variables declared inside of the
condition (both static and automatic) just change context, automatic
variables from the caller are turned into parameters (note, as the code
is never executed, I handle this way even non-POD types, we don't need to
bother pretending there would be user copy constructors etc. involved).

The assume_function artificial functions are then optimized until the
new assumptions pass which doesn't do much right now but I'd like to see
there the backwards ranger walk and filling up of SSA_NAME_RANGE_INFO
for the parameters.

There are a few further changes I'd like to do, like ignoring the
.ASSUME calls in inlining size estimations (but haven't figured out where
it is done), or for LTO arrange for the assume functions to be emitted
in all partitions that reference those (usually there will be just one,
unless code with the assumption got inlined, versioned etc.).

2022-10-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106654
gcc/
	* gimple.def (GIMPLE_ASSUME): New statement kind.
	* gimple.h (struct gimple_statement_assume): New type.
	(is_a_helper <gimple_statement_assume *>::test,
	is_a_helper <const gimple_statement_assume *>::test): New.
	(gimple_build_assume): Declare.
	(gimple_has_substatements): Return true for GIMPLE_ASSUME.
	(gimple_assume_guard, gimple_assume_set_guard,
	gimple_assume_guard_ptr, gimple_assume_body_ptr, gimple_assume_body):
	New inline functions.
	* gsstruct.def (GSS_ASSUME): New.
	* gimple.cc (gimple_build_assume): New function.
	(gimple_copy): Handle GIMPLE_ASSUME.
	* gimple-pretty-print.cc (dump_gimple_assume): New function.
	(pp_gimple_stmt_1): Handle GIMPLE_ASSUME.
	* gimple-walk.cc (walk_gimple_op): Handle GIMPLE_ASSUME.
	* omp-low.cc (WALK_SUBSTMTS): Likewise.
	(lower_omp_1): Likewise.
	* omp-oacc-kernels-decompose.cc (adjust_region_code_walk_stmt_fn):
	Likewise.
	* tree-cfg.cc (verify_gimple_stmt, verify_gimple_in_seq_2): Likewise.
	* function.h (struct function): Add assume_function bitfield.
	* gimplify.cc (gimplify_call_expr): If the assumption isn't
	simple enough, expand it into GIMPLE_ASSUME wrapped block or
	for -O0 drop it.
	* gimple-low.cc: Include attribs.h.
	(create_assumption_fn): New function.
	(struct lower_assumption_data): New type.
	(find_assumption_locals_r, assumption_copy_decl,
	adjust_assumption_stmt_r, adjust_assumption_stmt_op,
	lower_assumption): New functions.
	(lower_stmt): Handle GIMPLE_ASSUME.
	* tree-ssa-ccp.cc (pass_fold_builtins::execute): Remove
	IFN_ASSUME calls.
	* lto-streamer-out.cc (output_struct_function_base): Pack
	assume_function bit.
	* lto-streamer-in.cc (input_struct_function_base): And unpack it.
	* cgraphunit.cc (cgraph_node::expand): Don't verify assume_function
	has TREE_ASM_WRITTEN set and don't release its body.
	(symbol_table::compile): Allow assume functions not to have released
	body.
	* internal-fn.cc (expand_ASSUME): Remove gcc_unreachable.
	* passes.cc (execute_one_pass): For TODO_discard_function don't
	release body of assume functions.
	* cgraph.cc (cgraph_node::verify_node): Don't verify cgraph nodes
	of PROP_assumptions_done functions.
	* tree-pass.h (PROP_assumptions_done): Define.
	(TODO_discard_function): Adjust comment.
	(make_pass_assumptions): Declare.
	* passes.def (pass_assumptions): Add.
	* timevar.def (TV_TREE_ASSUMPTIONS): New.
	* tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_ASSUME.
	* tree-vrp.cc (pass_data_assumptions): New variable.
	(pass_assumptions): New class.
	(make_pass_assumptions): New function.
gcc/cp/
	* cp-tree.h (build_assume_call): Declare.
	* parser.cc (cp_parser_omp_assumption_clauses): Use build_assume_call.
	* cp-gimplify.cc (build_assume_call): New function.
	(process_stmt_assume_attribute): Use build_assume_call.
	* pt.cc (tsubst_copy_and_build): Likewise.
gcc/testsuite/
	* g++.dg/cpp23/attr-assume5.C: New test.
	* g++.dg/cpp23/attr-assume6.C: New test.
	* g++.dg/cpp23/attr-assume7.C: New test.
2022-10-18 10:39:09 +02:00
c++tools Daily bump. 2022-03-19 00:16:22 +00:00
config Daily bump. 2022-09-01 00:17:39 +00:00
contrib Daily bump. 2022-10-08 00:17:29 +00:00
fixincludes Daily bump. 2022-10-08 00:17:29 +00:00
gcc middle-end IFN_ASSUME support [PR106654] 2022-10-18 10:39:09 +02:00
gnattools Daily bump. 2022-09-01 00:17:39 +00:00
gotools Daily bump. 2022-08-31 00:16:45 +00:00
include Daily bump. 2022-10-14 00:16:35 +00:00
INSTALL
intl Daily bump. 2021-11-30 00:16:44 +00:00
libada Daily bump. 2022-08-26 00:16:21 +00:00
libatomic Daily bump. 2022-10-13 00:17:37 +00:00
libbacktrace Daily bump. 2022-10-13 00:17:37 +00:00
libcc1 Daily bump. 2022-10-13 00:17:37 +00:00
libcody Daily bump. 2022-06-04 00:16:27 +00:00
libcpp Daily bump. 2022-10-15 00:17:38 +00:00
libdecnumber Daily bump. 2022-10-08 00:17:29 +00:00
libffi Daily bump. 2022-10-13 00:17:37 +00:00
libgcc Daily bump. 2022-10-18 00:17:40 +00:00
libgfortran Daily bump. 2022-10-13 00:17:37 +00:00
libgo runtime: portable access to sigev_notify_thread_id 2022-09-27 09:30:23 -07:00
libgomp Daily bump. 2022-10-18 00:17:40 +00:00
libiberty Daily bump. 2022-10-15 00:17:38 +00:00
libitm Daily bump. 2022-10-14 00:16:35 +00:00
libobjc Daily bump. 2022-10-13 00:17:37 +00:00
liboffloadmic Daily bump. 2022-10-13 00:17:37 +00:00
libphobos Daily bump. 2022-10-13 00:17:37 +00:00
libquadmath Daily bump. 2022-10-13 00:17:37 +00:00
libsanitizer Daily bump. 2022-10-13 00:17:37 +00:00
libssp Daily bump. 2022-10-13 00:17:37 +00:00
libstdc++-v3 Daily bump. 2022-10-18 00:17:40 +00:00
libvtv Daily bump. 2022-10-13 00:17:37 +00:00
lto-plugin Daily bump. 2022-10-13 00:17:37 +00:00
maintainer-scripts Daily bump. 2022-07-29 00:16:21 +00:00
zlib Daily bump. 2022-10-13 00:17:37 +00:00
.dir-locals.el dir-locals: Use https for bug references 2021-07-20 11:40:34 +01:00
.gitattributes
.gitignore .gitignore: do not ignore config.h 2022-07-19 17:07:04 +03:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2022-10-13 00:17:37 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess config.sub, config.guess : Import upstream 2021-01-25. 2021-02-23 17:21:10 +08:00
config.rpath
config.sub config.sub: change mode to 755. 2021-12-21 09:10:57 +01:00
configure Arrange to --disable-shared by default for VxWorks 2022-09-30 10:43:13 +00:00
configure.ac Arrange to --disable-shared by default for VxWorks 2022-09-30 10:43:13 +00:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Generic configury support for shared libs on VxWorks 2022-10-11 07:31:07 +00:00
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS MAINTAINERS: Add myself for write after approval 2022-10-12 17:12:05 +08:00
Makefile.def Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
Makefile.in Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +01:00
Makefile.tpl Makefile.def: drop remnants of unused libelf 2022-08-18 09:37:09 +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.