]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add unsigned type iv_cand for iv_use with non mode-precision type
authorBin Cheng <bin.cheng@linux.alibaba.com>
Mon, 4 May 2020 06:28:54 +0000 (14:28 +0800)
committerBin Cheng <bin.cheng@linux.alibaba.com>
Mon, 4 May 2020 06:28:54 +0000 (14:28 +0800)
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.

Backport from master.
2020-04-09  Bin Cheng  <bin.cheng@linux.alibaba.com>
    PR tree-optimization/93674

gcc/
    * 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/
    * g++.dg/pr93674.C: New test.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr93674.C [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c

index e8b3131e7dfd82c9b67e349d7e35201ae3d3c6fa..ad1b048c73efcdb2a78c2e3c7943be9b97ec2f04 100644 (file)
@@ -1,3 +1,14 @@
+2020-05-04  Bin Cheng  <bin.cheng@linux.alibaba.com>
+
+       PR tree-optimization/93674
+       Backport from master
+       2020-04-09  Bin Cheng  <bin.cheng@linux.alibaba.com>
+
+       * 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-05-01  Alan Modra  <amodra@gmail.com>
 
        PR target/94145
index 52ca2715aff6a672b8d18137f71d9f286f16ea5d..5cafab95cc373f318aa5bc41b371dcd8c675d15a 100644 (file)
@@ -1,3 +1,11 @@
+2020-05-04  Bin Cheng  <bin.cheng@linux.alibaba.com>
+
+       PR tree-optimization/93674
+       Backport from master
+       2020-04-09  Bin Cheng  <bin.cheng@linux.alibaba.com>
+
+       * g++.dg/pr93674.C: New test.
+
 2020-05-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/93956
diff --git a/gcc/testsuite/g++.dg/pr93674.C b/gcc/testsuite/g++.dg/pr93674.C
new file mode 100644 (file)
index 0000000..8c59f1b
--- /dev/null
@@ -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" } }
index 01423dee883ed035937fd500ecfdb5c8b773136e..ecfa569259cdbd3fcd1f414b4947db8e9eacb701 100644 (file)
@@ -109,6 +109,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "tree-vectorizer.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.  */
@@ -3490,8 +3493,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);