aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-11-20 00:02:21 +0100
committerJakub Jelinek <jakub@redhat.com>2020-11-20 00:02:21 +0100
commitd3f293348768667c07770e433ff00af51fee73a2 (patch)
treee6772219b45c168901b54fe55de7384f1d27efbf /gcc/testsuite/gcc.dg
parentd0d8b5d83614d8f0d0e40c0520d4f40ffa01f8d9 (diff)
downloadgcc-d3f293348768667c07770e433ff00af51fee73a2.zip
gcc-d3f293348768667c07770e433ff00af51fee73a2.tar.gz
gcc-d3f293348768667c07770e433ff00af51fee73a2.tar.bz2
ranger: Improve a % b operand ranges [PR91029]
As mentioned in the PR, the previous PR91029 patch was testing op2 >= 0 which is unnecessary, even negative op2 values will work the same, furthermore, from if a % b > 0 we can deduce a > 0 rather than just a >= 0 (0 % b would be 0), and it actually valid even for other constants than 0, a % b > 5 means a > 5 (a % b has the same sign as a and a in [0, 5] would result in a % b in [0, 5]. Also, we can deduce a range for the other operand, if we know a % b >= 20, then b must be (in absolute value for signed modulo) > 20, for a % [0, 20] the result would be [0, 19]. 2020-11-19 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/91029 * range-op.cc (operator_trunc_mod::op1_range): Don't require signed types, nor require that op2 >= 0. Implement (a % b) >= x && x > 0 implies a >= x and (a % b) <= x && x < 0 implies a <= x. (operator_trunc_mod::op2_range): New method. * gcc.dg/tree-ssa/pr91029-1.c: New test. * gcc.dg/tree-ssa/pr91029-2.c: New test.
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr91029-1.c68
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr91029-2.c98
2 files changed, 166 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91029-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr91029-1.c
new file mode 100644
index 0000000..d52734b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91029-1.c
@@ -0,0 +1,68 @@
+/* PR tree-optimization/91029 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+void kill (void);
+int xx;
+
+void f1 (int i, int j)
+{
+ if ((i % j) == 3)
+ {
+ xx = (i < 3);
+ if (xx)
+ kill ();
+ }
+}
+
+void f2 (int i, int j)
+{
+ if ((i % j) > 0)
+ {
+ xx = (i <= 0);
+ if (xx)
+ kill ();
+ }
+}
+
+void f3 (int i, int j)
+{
+ if ((i % j) == -3)
+ {
+ xx = (i > -3);
+ if (xx)
+ kill ();
+ }
+}
+
+void f4 (int i, int j)
+{
+ if ((i % j) < 0)
+ {
+ xx = (i >= 0);
+ if (xx)
+ kill ();
+ }
+}
+
+void f5 (int i, int j)
+{
+ if ((i % j) > 42)
+ {
+ xx = (i <= 42);
+ if (xx)
+ kill ();
+ }
+}
+
+void f6 (int i, int j)
+{
+ if ((i % j) < -124)
+ {
+ xx = (i >= -124);
+ if (xx)
+ kill ();
+ }
+}
+
+/* { dg-final { scan-tree-dump-not "kill" "evrp" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91029-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr91029-2.c
new file mode 100644
index 0000000..ad9213a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr91029-2.c
@@ -0,0 +1,98 @@
+/* PR tree-optimization/91029 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+void kill (void);
+int xx;
+
+void f1 (int i, int j)
+{
+ if ((i % j) == 3)
+ {
+ xx = (j <= 3 && j >= -3);
+ if (xx)
+ kill ();
+ }
+}
+
+void f2 (int i, int j)
+{
+ if ((i % j) > 0)
+ {
+ xx = (j <= 1 && j >= -1);
+ if (xx)
+ kill ();
+ }
+}
+
+void f3 (int i, int j)
+{
+ if ((i % j) == -3)
+ {
+ xx = (j <= 3 && j >= -3);
+ if (xx)
+ kill ();
+ }
+}
+
+void f4 (int i, int j)
+{
+ if ((i % j) < 0)
+ {
+ xx = (j <= 1 && j >= -1);
+ if (xx)
+ kill ();
+ }
+}
+
+void f5 (int i, int j)
+{
+ if ((i % j) > 42)
+ {
+ xx = (j <= 43 && j >= -43);
+ if (xx)
+ kill ();
+ }
+}
+
+void f6 (int i, int j)
+{
+ if ((i % j) < -124)
+ {
+ xx = (j <= 125 && j >= -125);
+ if (xx)
+ kill ();
+ }
+}
+
+void f7 (unsigned int i, unsigned int j)
+{
+ if ((i % j) == 3)
+ {
+ xx = (j <= 3);
+ if (xx)
+ kill ();
+ }
+}
+
+void f8 (unsigned int i, unsigned int j)
+{
+ if ((i % j) > 0)
+ {
+ xx = (j <= 1);
+ if (xx)
+ kill ();
+ }
+}
+
+void f9 (unsigned int i, unsigned int j)
+{
+ if ((i % j) >= 124)
+ {
+ xx = (j <= 124);
+ if (xx)
+ kill ();
+ }
+}
+
+/* { dg-final { scan-tree-dump-not "kill" "evrp" } } */