public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* divmod transform: add test-cases
@ 2016-07-28 13:37 Prathamesh Kulkarni
  2016-08-09 10:58 ` Prathamesh Kulkarni
  0 siblings, 1 reply; 6+ messages in thread
From: Prathamesh Kulkarni @ 2016-07-28 13:37 UTC (permalink / raw)
  To: Richard Biener, Kugan Vivekanandarajah, Jim Wilson,
	Ramana Radhakrishnan, gcc Patches

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

Hi,
The following patch adds test-cases for divmod transform.
I separated the SImode tests into separate file from DImode tests
because certain arm configs (cortex-15) have hardware div insn for
SImode but not for DImode,
and for that config we want SImode tests to be disabled but not DImode tests.
The patch therefore has two target-effective checks: divmod and divmod_simode.
Is it OK for trunk ?

Thanks,
Prathamesh

[-- Attachment #2: divmod-1-tests.diff --]
[-- Type: text/plain, Size: 10299 bytes --]

diff --git a/gcc/testsuite/gcc.dg/divmod-1-simode.c b/gcc/testsuite/gcc.dg/divmod-1-simode.c
new file mode 100644
index 0000000..7405f66
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-1-simode.c
@@ -0,0 +1,22 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* div dominates mod.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)  \
+bigtype f_##no(smalltype x, bigtype y) \
+{					 \
+  bigtype q = x / y;                     \
+  if (cond)                              \
+    foo ();                              \
+  bigtype r = x % y;                     \
+  return q + r;                          \
+}
+
+FOO(int, int, 1)
+FOO(int, unsigned, 2)
+FOO(unsigned, unsigned, 5)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 3 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-1.c b/gcc/testsuite/gcc.dg/divmod-1.c
new file mode 100644
index 0000000..40aec74
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-1.c
@@ -0,0 +1,26 @@
+/* { dg-require-effective-target divmod } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* div dominates mod.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)	 \
+bigtype f_##no(smalltype x, bigtype y)   \
+{					 \
+  bigtype q = x / y;                     \
+  if (cond)                              \
+    foo ();                              \
+  bigtype r = x % y;                     \
+  return q + r;                          \
+}
+
+FOO(int, long long, 3)
+FOO(int, unsigned long long, 4)
+FOO(unsigned, long long, 6)
+FOO(unsigned, unsigned long long, 7)
+FOO(long long, long long, 8)
+FOO(long long, unsigned long long, 9)
+FOO(unsigned long long, unsigned long long, 10)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 7 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-2-simode.c b/gcc/testsuite/gcc.dg/divmod-2-simode.c
new file mode 100644
index 0000000..7c8313b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-2-simode.c
@@ -0,0 +1,22 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* mod dominates div.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)  \
+bigtype f_##no(smalltype x, bigtype y) \
+{					 \
+  bigtype r = x % y;                     \
+  if (cond)                              \
+    foo ();                              \
+  bigtype q = x / y;                     \
+  return q + r;                          \
+}
+
+FOO(int, int, 1)
+FOO(int, unsigned, 2)
+FOO(unsigned, unsigned, 5)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 3 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-2.c b/gcc/testsuite/gcc.dg/divmod-2.c
new file mode 100644
index 0000000..6a2216c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-2.c
@@ -0,0 +1,26 @@
+/* { dg-require-effective-target divmod } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* mod dominates div.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)	 \
+bigtype f_##no(smalltype x, bigtype y)   \
+{					 \
+  bigtype r = x % y;                     \
+  if (cond)                              \
+    foo ();                              \
+  bigtype q = x / y;                     \
+  return q + r;                          \
+}
+
+FOO(int, long long, 3)
+FOO(int, unsigned long long, 4)
+FOO(unsigned, long long, 6)
+FOO(unsigned, unsigned long long, 7)
+FOO(long long, long long, 8)
+FOO(long long, unsigned long long, 9)
+FOO(unsigned long long, unsigned long long, 10)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 7 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-3-simode.c b/gcc/testsuite/gcc.dg/divmod-3-simode.c
new file mode 100644
index 0000000..6f0f63d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-3-simode.c
@@ -0,0 +1,20 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* div comes before mod in same bb.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)  	 \
+bigtype f_##no(smalltype x, bigtype y)	 \
+{					 \
+  bigtype q = x / y;                     \
+  bigtype r = x % y;                     \
+  return q + r;                          \
+}
+
+FOO(int, int, 1)
+FOO(int, unsigned, 2)
+FOO(unsigned, unsigned, 5)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 3 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-3.c b/gcc/testsuite/gcc.dg/divmod-3.c
new file mode 100644
index 0000000..9fe6f64
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-3.c
@@ -0,0 +1,24 @@
+/* { dg-require-effective-target divmod } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* div comes before mod in same bb.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)      \
+bigtype f_##no(smalltype x, bigtype y)   \
+{					 \
+  bigtype q = x / y;                     \
+  bigtype r = x % y;                     \
+  return q + r;                          \
+}
+
+FOO(int, long long, 3)
+FOO(int, unsigned long long, 4)
+FOO(unsigned, long long, 6)
+FOO(unsigned, unsigned long long, 7)
+FOO(long long, long long, 8)
+FOO(long long, unsigned long long, 9)
+FOO(unsigned long long, unsigned long long, 10)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 7 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-4-simode.c b/gcc/testsuite/gcc.dg/divmod-4-simode.c
new file mode 100644
index 0000000..9c326f2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-4-simode.c
@@ -0,0 +1,20 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* mod comes before div in same bb.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)      \
+bigtype f_##no(smalltype x, bigtype y)   \
+{					 \
+  bigtype r = x % y;                     \
+  bigtype q = x / y;                     \
+  return q + r;                          \
+}
+
+FOO(int, int, 1)
+FOO(int, unsigned, 2)
+FOO(unsigned, unsigned, 5)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 3 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-4.c b/gcc/testsuite/gcc.dg/divmod-4.c
new file mode 100644
index 0000000..a5686cc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-4.c
@@ -0,0 +1,24 @@
+/* { dg-require-effective-target divmod } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* mod comes before div in same bb.  */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)	\
+bigtype f_##no(smalltype x, bigtype y)  \
+{					\
+  bigtype r = x % y;                    \
+  bigtype q = x / y;                    \
+  return q + r;                         \
+}
+
+FOO(int, long long, 3)
+FOO(int, unsigned long long, 4)
+FOO(unsigned, long long, 6)
+FOO(unsigned, unsigned long long, 7)
+FOO(long long, long long, 8)
+FOO(long long, unsigned long long, 9)
+FOO(unsigned long long, unsigned long long, 10)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 7 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-5.c b/gcc/testsuite/gcc.dg/divmod-5.c
new file mode 100644
index 0000000..8a8cee5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-5.c
@@ -0,0 +1,19 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+/* div and mod are not in same bb and
+   bb's containing div and mod don't dominate each other.  */
+
+int f(int x, int y)
+{
+  int q = 0;
+  int r = 0;
+  extern int cond;
+
+  if (cond)
+    q = x / y;
+
+  r = x % y;
+  return q + r;
+}
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 0 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-6-simode.c b/gcc/testsuite/gcc.dg/divmod-6-simode.c
new file mode 100644
index 0000000..3bf6fa3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-6-simode.c
@@ -0,0 +1,24 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)  \
+bigtype f_##no(smalltype x, bigtype y) \
+{					 \
+  bigtype q = x / y;                     \
+  bigtype r1 = 0, r2 = 0;                \
+  if (cond)                              \
+    r1 = x % y;                          \
+  else                                   \
+    r2 = x % y;                          \
+  return q + r1 + r2;                    \
+}
+
+FOO(int, int, 1)
+FOO(int, unsigned, 2)
+FOO(unsigned, unsigned, 5)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 3 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-6.c b/gcc/testsuite/gcc.dg/divmod-6.c
new file mode 100644
index 0000000..70e4321
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-6.c
@@ -0,0 +1,27 @@
+/* { dg-require-effective-target divmod } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+
+extern int cond;
+void foo(void);
+
+#define FOO(smalltype, bigtype, no)	 \
+bigtype f_##no(smalltype x, bigtype y)   \
+{					 \
+  bigtype q = x / y;                     \
+  bigtype r1 = 0, r2 = 0;                \
+  if (cond)                              \
+    r1 = x % y;                          \
+  else                                   \
+    r2 = x % y;                          \
+  return q + r1 + r2;                    \
+}
+
+FOO(int, long long, 3)
+FOO(int, unsigned long long, 4)
+FOO(unsigned, long long, 6)
+FOO(unsigned, unsigned long long, 7)
+FOO(long long, long long, 8)
+FOO(long long, unsigned long long, 9)
+FOO(unsigned long long, unsigned long long, 10)
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 7 "widening_mul" } } */
diff --git a/gcc/testsuite/gcc.dg/divmod-7.c b/gcc/testsuite/gcc.dg/divmod-7.c
new file mode 100644
index 0000000..faa90b3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/divmod-7.c
@@ -0,0 +1,21 @@
+/* { dg-require-effective-target divmod_simode } */
+/* { dg-options "-O2 -fdump-tree-widening_mul-details" } */
+
+int f(int x, int y)
+{
+  int q = 0, r1 = 0, r2 = 0;
+  extern int cond;
+
+  if (cond)
+    q = x / y;
+  else
+    {
+      r1 = x % y;
+      return q + r1;
+    }
+
+  r2 = x % y;
+  return q + r2;
+}
+
+/* { dg-final { scan-tree-dump-times "DIVMOD" 1 "widening_mul" } } */

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

* Re: divmod transform: add test-cases
  2016-07-28 13:37 divmod transform: add test-cases Prathamesh Kulkarni
@ 2016-08-09 10:58 ` Prathamesh Kulkarni
  2016-08-11 22:03   ` Jeff Law
  0 siblings, 1 reply; 6+ messages in thread
From: Prathamesh Kulkarni @ 2016-08-09 10:58 UTC (permalink / raw)
  To: Richard Biener, Kugan Vivekanandarajah, Jim Wilson,
	Ramana Radhakrishnan, gcc Patches

ping https://gcc.gnu.org/ml/gcc-patches/2016-07/msg01869.html

Thanks,
Prathamesh

On 28 July 2016 at 19:07, Prathamesh Kulkarni
<prathamesh.kulkarni@linaro.org> wrote:
> Hi,
> The following patch adds test-cases for divmod transform.
> I separated the SImode tests into separate file from DImode tests
> because certain arm configs (cortex-15) have hardware div insn for
> SImode but not for DImode,
> and for that config we want SImode tests to be disabled but not DImode tests.
> The patch therefore has two target-effective checks: divmod and divmod_simode.
> Is it OK for trunk ?
>
> Thanks,
> Prathamesh

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

* Re: divmod transform: add test-cases
  2016-08-09 10:58 ` Prathamesh Kulkarni
@ 2016-08-11 22:03   ` Jeff Law
  2016-08-12  7:17     ` Richard Biener
  0 siblings, 1 reply; 6+ messages in thread
From: Jeff Law @ 2016-08-11 22:03 UTC (permalink / raw)
  To: Prathamesh Kulkarni, Richard Biener, Kugan Vivekanandarajah,
	Jim Wilson, Ramana Radhakrishnan, gcc Patches

On 08/09/2016 04:58 AM, Prathamesh Kulkarni wrote:
> ping https://gcc.gnu.org/ml/gcc-patches/2016-07/msg01869.html
This seems to be dependent upon other patches, this is not OK until all 
prereqs are resolved.

You're using SI/DI in the descriptions, but then using more traditional 
C types like int, unsigned, long long in the actual test.

If you intent is really to nail down SI/DI mode testing, then the way to 
go will be to define typedefs that correspond directly to SI and DI modes:

typedef unsigned int u32 __attribute__((mode(SI)));
typedef signed int s32 __attribute__((mode(SI)));

You can do something similar for DImode.

It may not matter because of your effective-target 
{divmod,divmod_simode} selectors, but it still seems cleaner.

With that change, this is OK when its prereqs are resolved.

jeff


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

* Re: divmod transform: add test-cases
  2016-08-11 22:03   ` Jeff Law
@ 2016-08-12  7:17     ` Richard Biener
  2016-08-12 12:04       ` Prathamesh Kulkarni
  2016-08-15 17:01       ` Jeff Law
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Biener @ 2016-08-12  7:17 UTC (permalink / raw)
  To: Jeff Law
  Cc: Prathamesh Kulkarni, Kugan Vivekanandarajah, Jim Wilson,
	Ramana Radhakrishnan, gcc Patches

On Thu, 11 Aug 2016, Jeff Law wrote:

> On 08/09/2016 04:58 AM, Prathamesh Kulkarni wrote:
> > ping https://gcc.gnu.org/ml/gcc-patches/2016-07/msg01869.html
> This seems to be dependent upon other patches, this is not OK until all
> prereqs are resolved.
> 
> You're using SI/DI in the descriptions, but then using more traditional C
> types like int, unsigned, long long in the actual test.
> 
> If you intent is really to nail down SI/DI mode testing, then the way to go
> will be to define typedefs that correspond directly to SI and DI modes:
> 
> typedef unsigned int u32 __attribute__((mode(SI)));
> typedef signed int s32 __attribute__((mode(SI)));
> 
> You can do something similar for DImode.
> 
> It may not matter because of your effective-target {divmod,divmod_simode}
> selectors, but it still seems cleaner.
> 
> With that change, this is OK when its prereqs are resolved.

Note that for the main patch I don't like the current state of the
divmod libcall issue.  I think we need to solve this in a more
reasonable manner and not expose this oddness to a GIMPLE level pass.

Any ideas welcome - I don't have a very good one :/

The best idea I have is to not lie about libfunc availability in
the optab handler.

Richard.

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

* Re: divmod transform: add test-cases
  2016-08-12  7:17     ` Richard Biener
@ 2016-08-12 12:04       ` Prathamesh Kulkarni
  2016-08-15 17:01       ` Jeff Law
  1 sibling, 0 replies; 6+ messages in thread
From: Prathamesh Kulkarni @ 2016-08-12 12:04 UTC (permalink / raw)
  To: Richard Biener
  Cc: Jeff Law, Kugan Vivekanandarajah, Jim Wilson,
	Ramana Radhakrishnan, gcc Patches

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

On 12 August 2016 at 12:47, Richard Biener <rguenther@suse.de> wrote:
> On Thu, 11 Aug 2016, Jeff Law wrote:
>
>> On 08/09/2016 04:58 AM, Prathamesh Kulkarni wrote:
>> > ping https://gcc.gnu.org/ml/gcc-patches/2016-07/msg01869.html
>> This seems to be dependent upon other patches, this is not OK until all
>> prereqs are resolved.
>>
>> You're using SI/DI in the descriptions, but then using more traditional C
>> types like int, unsigned, long long in the actual test.
>>
>> If you intent is really to nail down SI/DI mode testing, then the way to go
>> will be to define typedefs that correspond directly to SI and DI modes:
>>
>> typedef unsigned int u32 __attribute__((mode(SI)));
>> typedef signed int s32 __attribute__((mode(SI)));
>>
>> You can do something similar for DImode.
>>
>> It may not matter because of your effective-target {divmod,divmod_simode}
>> selectors, but it still seems cleaner.
>>
>> With that change, this is OK when its prereqs are resolved.
>
> Note that for the main patch I don't like the current state of the
> divmod libcall issue.  I think we need to solve this in a more
> reasonable manner and not expose this oddness to a GIMPLE level pass.
>
> Any ideas welcome - I don't have a very good one :/
>
> The best idea I have is to not lie about libfunc availability in
> the optab handler.
Hi,
In the attached patch I set libfunc entry for sdivmod_optab to NULL
and verified that optab_libfunc (sdivmod_optab, DImode) returns NULL_RTX
if it's not overriden by the target.

AFAIU this issue could be latent in expand_twoval_binop_libfunc,
and apparently never got triggered for the default case, where target
doesn't override
optab_libfunc (sdivmod_optab, DImode) else it could have generated
call to __divmoddi4() which doesn't exist

Bootstrapped and tested on ppc64le-linux-gnu,
Cross-tested on arm*-*-*, aarch64*-*-*.
Bootstrap+test in progress on x86_64-unknown-linux-gnu.

OK to commit if passes ?

Thanks,
Prathamesh
>
> Richard.

[-- Attachment #2: sdivmod_optab.diff --]
[-- Type: text/plain, Size: 790 bytes --]

diff --git a/gcc/optabs.def b/gcc/optabs.def
index 8875e30..305f8c0 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -116,7 +116,7 @@ OPTAB_NL(ssdiv_optab, "ssdiv$Q$a3", SS_DIV, "ssdiv", '3', gen_signed_fixed_libfu
 OPTAB_NL(udiv_optab, "udiv$I$a3", UDIV, "udiv", '3', gen_int_unsigned_fixed_libfunc)
 OPTAB_NX(udiv_optab, "udiv$Q$a3")
 OPTAB_NL(usdiv_optab, "usdiv$Q$a3", US_DIV, "usdiv", '3', gen_unsigned_fixed_libfunc)
-OPTAB_NL(sdivmod_optab, "divmod$a4", UNKNOWN, "divmod", '4', gen_int_libfunc)
+OPTAB_NL(sdivmod_optab, "divmod$a4", UNKNOWN, "divmod", '4', NULL) 
 OPTAB_NL(udivmod_optab, "udivmod$a4", UNKNOWN, "udivmod", '4', gen_int_libfunc)
 OPTAB_NL(smod_optab, "mod$a3", MOD, "mod", '3', gen_int_libfunc)
 OPTAB_NL(umod_optab, "umod$a3", UMOD, "umod", '3', gen_int_libfunc)

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

* Re: divmod transform: add test-cases
  2016-08-12  7:17     ` Richard Biener
  2016-08-12 12:04       ` Prathamesh Kulkarni
@ 2016-08-15 17:01       ` Jeff Law
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff Law @ 2016-08-15 17:01 UTC (permalink / raw)
  To: Richard Biener
  Cc: Prathamesh Kulkarni, Kugan Vivekanandarajah, Jim Wilson,
	Ramana Radhakrishnan, gcc Patches

On 08/12/2016 01:17 AM, Richard Biener wrote:
>
> Note that for the main patch I don't like the current state of the
> divmod libcall issue.  I think we need to solve this in a more
> reasonable manner and not expose this oddness to a GIMPLE level pass.
I haven't looked at the main patch at all.

>
> Any ideas welcome - I don't have a very good one :/
>
> The best idea I have is to not lie about libfunc availability in
> the optab handler.
Hard to argue with "to not lie about ...".

jeff

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

end of thread, other threads:[~2016-08-15 17:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-28 13:37 divmod transform: add test-cases Prathamesh Kulkarni
2016-08-09 10:58 ` Prathamesh Kulkarni
2016-08-11 22:03   ` Jeff Law
2016-08-12  7:17     ` Richard Biener
2016-08-12 12:04       ` Prathamesh Kulkarni
2016-08-15 17:01       ` Jeff Law

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