[ldist] Don't add lib calls with -fno-tree-loop-distribute-patterns

As mentioned in PR56888 comment 21:
...
-fno-tree-loop-distribute-patterns is the reliable way to not
transform loops into library calls.
...

However, since commit 6f966f0614 ("ldist: Recognize strlen and rawmemchr like
loops") a strlen or rawmemchr library call may be introduced by ldist.

This caused regressions in testcases
gcc.c-torture/execute/builtins/strlen{,-2,-3}.c for nvptx.

Fix this by not calling transform_reduction_loop from
loop_distribution::execute for -fno-tree-loop-distribute-patterns.

Tested regressed test-cases as well as gcc.dg/tree-ssa/ldist-*.c on
nvptx.

gcc/ChangeLog:

2022-01-31  Tom de Vries  <tdevries@suse.de>

	* tree-loop-distribution.cc (generate_reduction_builtin_1): Check for
	-ftree-loop-distribute-patterns.
	(loop_distribution::execute): Don't call transform_reduction_loop for
	-fno-tree-loop-distribute-patterns.

gcc/testsuite/ChangeLog:

2022-01-31  Tom de Vries  <tdevries@suse.de>

	* gcc.dg/tree-ssa/ldist-strlen-4.c: New test.
This commit is contained in:
Tom de Vries 2022-01-31 17:05:28 +01:00
parent 1bb5266257
commit 2989516651
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,17 @@
/* { dg-do compile } */
/* { dg-options "-O2 -ftree-loop-distribution -fno-tree-loop-distribute-patterns -fdump-tree-ldist-details" } */
/* { dg-final { scan-tree-dump-not "generated strlen" "ldist" } } */
/* Copied from gcc/testsuite/gcc.c-torture/execute/builtins/lib/strlen.c. */
__SIZE_TYPE__
foo (const char *s)
{
__SIZE_TYPE__ i;
i = 0;
while (s[i] != 0)
i++;
return i;
}

View file

@ -3290,6 +3290,8 @@ generate_reduction_builtin_1 (loop_p loop, gimple_seq &seq,
tree reduction_var_old, tree reduction_var_new,
const char *info, machine_mode load_mode)
{
gcc_assert (flag_tree_loop_distribute_patterns);
/* Place new statements before LOOP. */
gimple_stmt_iterator gsi = gsi_last_bb (loop_preheader_edge (loop)->src);
gsi_insert_seq_after (&gsi, seq, GSI_CONTINUE_LINKING);
@ -3773,7 +3775,8 @@ loop_distribution::execute (function *fun)
if (niters == NULL_TREE || niters == chrec_dont_know)
{
datarefs_vec.create (20);
if (transform_reduction_loop (loop))
if (flag_tree_loop_distribute_patterns
&& transform_reduction_loop (loop))
{
changed = true;
loops_to_be_destroyed.safe_push (loop);