public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Check type size for doloop iv on BITS_PER_WORD [PR61837]
@ 2021-07-09  2:07 Jiufu Guo
  2021-07-09  6:43 ` Richard Biener
  0 siblings, 1 reply; 20+ messages in thread
From: Jiufu Guo @ 2021-07-09  2:07 UTC (permalink / raw)
  To: gcc-patches
  Cc: guojiufu, wschmidt, segher, dje.gcc, rguenther, jlaw, amker.cheng

Currently, doloop.xx variable is using the type as niter which may shorter
than word size.  For some cases, it may be better to use word size type.
For example, on some 64bit system, to access 32bit niter, subreg maybe used.
Then using 64bit type would not need to use subreg if the value can be
present in both 32bit and 64bit.

This patch updates doloop iv to BIT_PER_WORD size if it is fine.

Bootstrap and regtest pass on powerpc64le and x86, is this ok for trunk?

BR.
Jiufu

gcc/ChangeLog:

2021-07-08  Jiufu Guo  <guojiufu@linux.ibm.com>

	PR target/61837
	* tree-ssa-loop-ivopts.c (add_iv_candidate_for_doloop):
	Update iv on BITS_PER_WORD for niter.

gcc/testsuite/ChangeLog:

2021-07-08  Jiufu Guo  <guojiufu@linux.ibm.com>

	PR target/61837
	* gcc.target/powerpc/pr61837.c: New test.

---
 gcc/testsuite/gcc.target/powerpc/pr61837.c | 16 ++++++++++++++++
 gcc/tree-ssa-loop-ivopts.c                 | 10 ++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr61837.c

diff --git a/gcc/testsuite/gcc.target/powerpc/pr61837.c b/gcc/testsuite/gcc.target/powerpc/pr61837.c
new file mode 100644
index 00000000000..dc44eb9cb41
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr61837.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+void foo(int *p1, long *p2, int s)
+{
+  int n, v, i;
+
+  v = 0;
+  for (n = 0; n <= 100; n++) {
+     for (i = 0; i < s; i++)
+        if (p2[i] == n)
+           p1[i] = v;
+     v += 88;
+  }
+}
+
+/* { dg-final { scan-assembler-not {\mrldicl\M} } } */
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 12a8a49a307..c3c2f97918d 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -5690,6 +5690,16 @@ add_iv_candidate_for_doloop (struct ivopts_data *data)
 
   tree base = fold_build2 (PLUS_EXPR, ntype, unshare_expr (niter),
 			   build_int_cst (ntype, 1));
+
+  /* Use type in word size may fast.  */
+  if (TYPE_PRECISION (ntype) < BITS_PER_WORD
+      && TYPE_PRECISION (long_unsigned_type_node) == BITS_PER_WORD
+      && wi::ltu_p (niter_desc->max, wi::to_widest (TYPE_MAX_VALUE (ntype))))
+    {
+      ntype = long_unsigned_type_node;
+      base = fold_convert (ntype, base);
+    }
+
   add_candidate (data, base, build_int_cst (ntype, -1), true, NULL, NULL, true);
 }
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-07-14  7:18 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09  2:07 [PATCH] Check type size for doloop iv on BITS_PER_WORD [PR61837] Jiufu Guo
2021-07-09  6:43 ` Richard Biener
2021-07-09 17:08   ` Segher Boessenkool
2021-07-12  6:20     ` Richard Biener
2021-07-12  8:21       ` guojiufu
2021-07-12  8:57         ` Richard Biener
2021-07-12  9:43           ` guojiufu
2021-07-12 10:02             ` Richard Biener
2021-07-12 14:08               ` guojiufu
2021-07-12 14:46                 ` Richard Biener
2021-07-12 15:53                   ` guojiufu
2021-07-12 15:59                     ` guojiufu
2021-07-13  2:09                     ` guojiufu
2021-07-13  7:09                       ` Richard Biener
2021-07-13  8:16                         ` guojiufu
2021-07-13 15:51                       ` Segher Boessenkool
2021-07-14  2:38                         ` guojiufu
2021-07-13 15:38       ` Segher Boessenkool
2021-07-14  3:10         ` guojiufu
2021-07-14  7:17           ` Richard Biener

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).