public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH][ldist] Don't add lib calls with -fno-tree-loop-distribute-patterns
Date: Mon, 31 Jan 2022 17:26:51 +0100	[thread overview]
Message-ID: <3b14d728-35d3-251a-44b8-e152b92d5dd5@suse.de> (raw)
In-Reply-To: <CAFiYyc28QtFcpFNcSDrVkWxzD1ka6WqD4=bDr6u1pFChwzi+FA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2045 bytes --]

[ was: Re: [RFC] ldist: Recognize rawmemchr loop patterns ]

On 1/31/22 16:00, Richard Biener wrote:
>> I'm running into PR56888 (
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 ) on nvptx due to
>> this, f.i. in gcc/testsuite/gcc.c-torture/execute/builtins/strlen.c,
>> where gcc/testsuite/gcc.c-torture/execute/builtins/lib/strlen.c contains
>> a strlen function, with a strlen loop, which is transformed by
>> pass_loop_distribution into a __builtin_strlen, which is then expanded
>> into a strlen call, creating a self-recursive function. [ And on nvptx,
>> that happens to result in a compilation failure, which is how I found
>> this. ]
>>
>> According to this (
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888#c21 ) comment:
>> ...
>> -fno-tree-loop-distribute-patterns is the reliable way to not
>> transform loops into library calls.
>> ...
>>
>> Then should we have something along the lines of:
>> ...
>> $ git diff
>> diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
>> index 6fe59cd56855..9a211d30cd7e 100644
>> --- a/gcc/tree-loop-distribution.c
>> +++ b/gcc/tree-loop-distribution.c
>> @@ -3683,7 +3683,11 @@ loop_distribution::transform_reduction_loop
>>                  && TYPE_PRECISION (ptr_type_node) >= 32)
>>                 || (TYPE_OVERFLOW_UNDEFINED (reduction_var_type)
>>                     && TYPE_PRECISION (reduction_var_type) <=
>> TYPE_PRECISION (sizetype)))
>> -         && builtin_decl_implicit (BUILT_IN_STRLEN))
>> +         && builtin_decl_implicit (BUILT_IN_STRLEN)
>> +         && flag_tree_loop_distribute_patterns)
>>           generate_strlen_builtin (loop, reduction_var, load_iv.base,
>>                                    reduction_iv.base, loc);
>>          else if (direct_optab_handler (rawmemchr_optab, TYPE_MODE
>> (load_type))
>> ...
>> ?
>>
>> Or is the comment no longer valid?
> 
> It is still valid - and yes, I think we need to guard it with this flag
> but please do it in the caller to transform_reduction_loop.

Done.

Ok for trunk?

Thanks,
- Tom

[-- Attachment #2: 0001-ldist-Don-t-add-lib-calls-with-fno-tree-loop-distribute-patterns.patch --]
[-- Type: text/x-patch, Size: 2883 bytes --]

[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 6f966f06146 ("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 regressing 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.

---
 gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-4.c | 17 +++++++++++++++++
 gcc/tree-loop-distribution.cc                  |  5 ++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-4.c b/gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-4.c
new file mode 100644
index 000000000000..eafb37e84fc3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ldist-strlen-4.c
@@ -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;
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 6fe59cd56855..c7b428572636 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -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);

  reply	other threads:[~2022-01-31 16:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 12:47 [RFC] ldist: Recognize rawmemchr loop patterns Stefan Schulze Frielinghaus
2021-02-09  8:57 ` Richard Biener
2021-02-14 10:27   ` Stefan Schulze Frielinghaus
2021-02-25 17:01     ` Stefan Schulze Frielinghaus
2021-02-25 23:49       ` Jeff Law
2021-03-02 12:29     ` Richard Biener
2021-03-03 17:17       ` Stefan Schulze Frielinghaus
2021-03-16 17:13         ` Stefan Schulze Frielinghaus
2021-04-08  8:23           ` Stefan Schulze Frielinghaus
2021-05-04 17:25             ` Stefan Schulze Frielinghaus
2021-05-05  9:36           ` Richard Biener
2021-05-05 10:03             ` Richard Biener
2021-05-07 12:32             ` Stefan Schulze Frielinghaus
2021-05-20  9:24               ` Richard Biener
2021-05-20 18:37                 ` Stefan Schulze Frielinghaus
2021-06-14 17:26                   ` Stefan Schulze Frielinghaus
2021-06-16 14:22                     ` Richard Biener
2021-06-25 10:23                       ` Stefan Schulze Frielinghaus
2021-08-06 14:02                         ` Stefan Schulze Frielinghaus
2021-08-20 10:35                         ` Richard Biener
2021-09-03  8:00                           ` Stefan Schulze Frielinghaus
2021-09-06  9:56                             ` Richard Biener
2021-09-13 14:53                               ` Stefan Schulze Frielinghaus
2021-09-17  8:08                                 ` Richard Biener
2021-10-11 16:02                                   ` Stefan Schulze Frielinghaus
2022-01-31 13:16                                   ` Tom de Vries
2022-01-31 15:00                                     ` Richard Biener
2022-01-31 16:26                                       ` Tom de Vries [this message]
2022-02-01  7:04                                         ` [PATCH][ldist] Don't add lib calls with -fno-tree-loop-distribute-patterns Richard Biener

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=3b14d728-35d3-251a-44b8-e152b92d5dd5@suse.de \
    --to=tdevries@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    --cc=stefansf@linux.ibm.com \
    /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).