diff options
author | Bin Cheng <bin.cheng@linux.alibaba.com> | 2020-04-09 16:42:48 +0800 |
---|---|---|
committer | Bin Cheng <bin.cheng@linux.alibaba.com> | 2020-04-09 16:42:48 +0800 |
commit | ed80b385418f97ef087f3f2bbe1abecffb5c9775 (patch) | |
tree | 2e2fac8703977db8d148db11dbd3931b73013f7f | |
parent | 926d39c3816772acde857a8510480d9b287ef760 (diff) | |
download | gcc-ed80b385418f97ef087f3f2bbe1abecffb5c9775.zip gcc-ed80b385418f97ef087f3f2bbe1abecffb5c9775.tar.gz gcc-ed80b385418f97ef087f3f2bbe1abecffb5c9775.tar.bz2 |
Add unsigned type iv_cand for iv_use with non mode-precision type
Precisely, for iv_use if it's not integer/pointer type, or non-mode
precision type, add candidate for the corresponding scev in unsigned
type with the same precision, rather than its original type.
gcc/
PR tree-optimization/93674
* tree-ssa-loop-ivopts.c (langhooks.h): New include.
(add_iv_candidate_for_use): For iv_use of non integer or pointer type,
or non-mode precision type, add candidate in unsigned type with the
same precision.
gcc/testsuite/
PR tree-optimization/93674
* g++.dg/pr93674.C: New test.
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/pr93674.C | 16 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-ivopts.c | 18 |
4 files changed, 47 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d1819da..d45d272 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2020-04-09 Bin Cheng <bin.cheng@linux.alibaba.com> + Richard Biener <rguenther@suse.de> + + PR tree-optimization/93674 + * tree-ssa-loop-ivopts.c (langhooks.h): New include. + (add_iv_candidate_for_use): For iv_use of non integer or pointer type, + or non-mode precision type, add candidate in unsigned type with the + same precision. + 2020-04-08 Clement Chigot <clement.chigot@atos.net> * config/rs6000/aix61.h (LIB_SPEC): Add -lc128 with -mlong-double-128. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 45e7005..960eae4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-09 Bin Cheng <bin.cheng@linux.alibaba.com> + + PR tree-optimization/93674 + * g++.dg/pr93674.C: New test. + 2020-04-08 Sandra Loosemore <sandra@codesourcery.com> * g++.dg/tree-ssa/pr93940.C: Require pthread target. diff --git a/gcc/testsuite/g++.dg/pr93674.C b/gcc/testsuite/g++.dg/pr93674.C new file mode 100644 index 0000000..8c59f1b --- /dev/null +++ b/gcc/testsuite/g++.dg/pr93674.C @@ -0,0 +1,16 @@ +// { dg-do compile } +// { dg-options "-O3 -std=c++14 -fstrict-enums -pedantic -fdump-tree-optimized" } +enum some_enum { x = 1000 }; +void sink(some_enum); + +int __attribute__((noinline)) func() { + int sum = 0; + for (int i = 0; i < 3; ++i) { + for (int j = 3; j >= 0; --j) { + sink((some_enum)(i + j)); + } + } + return sum; +} + +// { dg-final { scan-tree-dump-not "some_enum ivtmp" "optimized" } } diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 1ce6d8b..1d2697a 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -132,6 +132,9 @@ along with GCC; see the file COPYING3. If not see #include "tree-vectorizer.h" #include "dbgcnt.h" +/* For lang_hooks.types.type_for_mode. */ +#include "langhooks.h" + /* FIXME: Expressions are expanded to RTL in this pass to determine the cost of different addressing modes. This should be moved to a TBD interface between the GIMPLE and RTL worlds. */ @@ -3479,8 +3482,21 @@ add_iv_candidate_for_use (struct ivopts_data *data, struct iv_use *use) { poly_uint64 offset; tree base; - tree basetype; struct iv *iv = use->iv; + tree basetype = TREE_TYPE (iv->base); + + /* Don't add candidate for iv_use with non integer, pointer or non-mode + precision types, instead, add candidate for the corresponding scev in + unsigned type with the same precision. See PR93674 for more info. */ + if ((TREE_CODE (basetype) != INTEGER_TYPE && !POINTER_TYPE_P (basetype)) + || !type_has_mode_precision_p (basetype)) + { + basetype = lang_hooks.types.type_for_mode (TYPE_MODE (basetype), + TYPE_UNSIGNED (basetype)); + add_candidate (data, fold_convert (basetype, iv->base), + fold_convert (basetype, iv->step), false, NULL); + return; + } add_candidate (data, iv->base, iv->step, false, use); |