Commit df7d46d9 by Robin Dapp Committed by Robin Dapp

[PATCH 2/2] Add simplify rule for wrapped addition.

Add the transform (T)(A) + CST -> (T)(A + CST).  This enables vrp to
simplify sequences like

_2 = a_7 - 1;
_3 = (long unsigned int) _2;
_5 = _3 + 1

that ivopts creates.

--

gcc/ChangeLog:

2019-08-26  Robin Dapp  <rdapp@linux.ibm.com>

        * match.pd: Add (T)(A) + CST -> (T)(A + CST).

gcc/testsuite/ChangeLog:

2019-08-26  Robin Dapp  <rdapp@linux.ibm.com>

        * gcc.dg/tree-ssa/copy-headers-5.c: Do not run vrp pass.
        * gcc.dg/tree-ssa/copy-headers-7.c: Do not run vrp pass.
        * gcc.dg/tree-ssa/loop-15.c: Remove XFAIL.
        * gcc.dg/tree-ssa/pr23744.c: Change search pattern.
        * gcc.dg/wrapped-binop-simplify.c: New test.

From-SVN: r274925
parent e944354e
2019-08-26 Robin Dapp <rdapp@linux.ibm.com> 2019-08-26 Robin Dapp <rdapp@linux.ibm.com>
* match.pd: Add (T)(A) + CST -> (T)(A + CST).
2019-08-26 Robin Dapp <rdapp@linux.ibm.com>
* gimple-loop-versioning.cc (loop_versioning::record_address_fragment): * gimple-loop-versioning.cc (loop_versioning::record_address_fragment):
Add nop_convert case. Add nop_convert case.
* tree-ssa-propagate.c (substitute_and_fold_dom_walker::before_dom_children): * tree-ssa-propagate.c (substitute_and_fold_dom_walker::before_dom_children):
......
...@@ -2022,6 +2022,37 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -2022,6 +2022,37 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (cst && !TREE_OVERFLOW (cst)) (if (cst && !TREE_OVERFLOW (cst))
(plus { cst; } @0)))) (plus { cst; } @0))))
/* ((T)(A)) + CST -> (T)(A + CST) */
#if GIMPLE
(simplify
(plus (convert SSA_NAME@0) INTEGER_CST@1)
(if (TREE_CODE (TREE_TYPE (@0)) == INTEGER_TYPE
&& TREE_CODE (type) == INTEGER_TYPE
&& TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@0))
&& int_fits_type_p (@1, TREE_TYPE (@0)))
/* Perform binary operation inside the cast if the constant fits
and (A + CST)'s range does not overflow. */
(with
{
wi::overflow_type min_ovf = wi::OVF_OVERFLOW,
max_ovf = wi::OVF_OVERFLOW;
tree inner_type = TREE_TYPE (@0);
wide_int w1 = wide_int::from (wi::to_wide (@1), TYPE_PRECISION (inner_type),
TYPE_SIGN (inner_type));
wide_int wmin0, wmax0;
if (get_range_info (@0, &wmin0, &wmax0) == VR_RANGE)
{
wi::add (wmin0, w1, TYPE_SIGN (inner_type), &min_ovf);
wi::add (wmax0, w1, TYPE_SIGN (inner_type), &max_ovf);
}
}
(if (min_ovf == wi::OVF_NONE && max_ovf == wi::OVF_NONE)
(convert (plus @0 { wide_int_to_tree (TREE_TYPE (@0), w1); } )))
)))
#endif
/* ~A + A -> -1 */ /* ~A + A -> -1 */
(simplify (simplify
(plus:c (bit_not @0) @0) (plus:c (bit_not @0) @0)
......
2019-08-26 Robin Dapp <rdapp@linux.ibm.com>
* gcc.dg/tree-ssa/copy-headers-5.c: Do not run vrp pass.
* gcc.dg/tree-ssa/copy-headers-7.c: Do not run vrp pass.
* gcc.dg/tree-ssa/loop-15.c: Remove XFAIL.
* gcc.dg/tree-ssa/pr23744.c: Change search pattern.
* gcc.dg/wrapped-binop-simplify.c: New test.
2019-08-26 Kito Cheng <kito.cheng@sifive.com> 2019-08-26 Kito Cheng <kito.cheng@sifive.com>
* gcc.target/riscv/li.c: New test. * gcc.target/riscv/li.c: New test.
......
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-ch2-details" } */ /* { dg-options "-O2 -fno-tree-vrp -fdump-tree-ch2-details" } */
int is_sorted(int *a, int n) int is_sorted(int *a, int n)
{ {
......
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-ch2-details --param logical-op-non-short-circuit=0" } */ /* { dg-options "-O2 -fno-tree-vrp -fdump-tree-ch2-details --param logical-op-non-short-circuit=0" } */
int is_sorted(int *a, int n, int m, int k) int is_sorted(int *a, int n, int m, int k)
{ {
......
...@@ -19,7 +19,7 @@ int bla(void) ...@@ -19,7 +19,7 @@ int bla(void)
} }
/* Since the loop is removed, there should be no addition. */ /* Since the loop is removed, there should be no addition. */
/* { dg-final { scan-tree-dump-times " \\+ " 0 "optimized" { xfail *-*-* } } } */ /* { dg-final { scan-tree-dump-times " \\+ " 0 "optimized" } } */
/* { dg-final { scan-tree-dump-times " \\* " 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times " \\* " 1 "optimized" } } */
/* The if from the loop header copying remains in the code. */ /* The if from the loop header copying remains in the code. */
......
/* { dg-do compile } */ /* { dg-do compile } */
/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1" } */ /* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1-details" } */
void h (void); void h (void);
...@@ -17,4 +17,4 @@ int g (int i, int j) ...@@ -17,4 +17,4 @@ int g (int i, int j)
return 1; return 1;
} }
/* { dg-final { scan-tree-dump-times "Folding predicate.*to 1" 1 "vrp1" } } */ /* { dg-final { scan-tree-dump-times "gimple_simplified" 1 "vrp1" } } */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-vrp2-details" } */
/* { dg-final { scan-tree-dump-times "gimple_simplified to" 4 "vrp2" } } */
void v1 (unsigned long *in, unsigned long *out, unsigned int n)
{
int i;
for (i = 0; i < n; i++)
{
out[i] = in[i];
}
}
void v2 (unsigned long *in, unsigned long *out, int n)
{
int i;
for (i = 0; i < n; i++)
{
out[i] = in[i];
}
}
void v3 (unsigned long *in, unsigned long *out, unsigned int n)
{
unsigned int i;
for (i = 0; i < n; i++)
{
out[i] = in[i];
}
}
void v4 (unsigned long *in, unsigned long *out, int n)
{
unsigned int i;
for (i = 0; i < n; i++)
{
out[i] = in[i];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment