]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Read global value/mask in IPA.
authorAldy Hernandez <aldyh@redhat.com>
Fri, 14 Jul 2023 10:38:16 +0000 (12:38 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Thu, 3 Aug 2023 20:31:34 +0000 (22:31 +0200)
Instead of reading the known zero bits in IPA, read the value/mask
pair which is available.

There is a slight change of behavior here.  I have removed the check
for SSA_NAME, as the ranger can calculate the range and value/mask for
INTEGER_CST.  This simplifies the code a bit, since there's no special
casing when setting the jfunc bits.  The default range for VR is
undefined, so I think it's safe just to check for undefined_p().

gcc/ChangeLog:

* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Read global
value/mask.

gcc/testsuite/ChangeLog:

* g++.dg/ipa/pure-const-3.C: Move source to...
* g++.dg/ipa/pure-const-3.h: ...here, and adjust original test
accordingly.
* g++.dg/ipa/pure-const-3b.C: New.

gcc/ipa-prop.cc
gcc/testsuite/g++.dg/ipa/pure-const-3.C
gcc/testsuite/g++.dg/ipa/pure-const-3.h [new file with mode: 0644]
gcc/testsuite/g++.dg/ipa/pure-const-3b.C [new file with mode: 0644]

index 5d790ff12658be89854ff497e318601268b423ca..4f6ed7b89bd789b3840a014dca132b07448c2909 100644 (file)
@@ -2402,8 +2402,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
        }
       else
        {
-         if (TREE_CODE (arg) == SSA_NAME
-             && param_type
+         if (param_type
              && Value_Range::supports_type_p (TREE_TYPE (arg))
              && Value_Range::supports_type_p (param_type)
              && irange::supports_p (TREE_TYPE (arg))
@@ -2422,15 +2421,14 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
            gcc_assert (!jfunc->m_vr);
        }
 
-      if (INTEGRAL_TYPE_P (TREE_TYPE (arg))
-         && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST))
+      if (INTEGRAL_TYPE_P (TREE_TYPE (arg)) && !vr.undefined_p ())
        {
-         if (TREE_CODE (arg) == SSA_NAME)
-           ipa_set_jfunc_bits (jfunc, 0,
-                               widest_int::from (get_nonzero_bits (arg),
-                                                 TYPE_SIGN (TREE_TYPE (arg))));
-         else
-           ipa_set_jfunc_bits (jfunc, wi::to_widest (arg), 0);
+         irange &r = as_a <irange> (vr);
+         irange_bitmask bm = r.get_bitmask ();
+         signop sign = TYPE_SIGN (TREE_TYPE (arg));
+         ipa_set_jfunc_bits (jfunc,
+                             widest_int::from (bm.value (), sign),
+                             widest_int::from (bm.mask (), sign));
        }
       else if (POINTER_TYPE_P (TREE_TYPE (arg)))
        {
index b4a4673e86ea9daa2433cd9313c9159ea0d2eef1..62d355b4ce7e37c2e1a60e16d9ea30e0b2caf713 100644 (file)
@@ -1,32 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp"  } */
-int *ptr;
-static int barvar;
-static int b(int a);
-/* We can not detect A to be const because it may be interposed by unoptimized
-   body.  */
-inline
-__attribute__ ((noinline))
-int a(int a)
-{
-  if (a>0)
-    return b(a-1);
-  return *ptr == *ptr;
-}
-inline
-__attribute__ ((noinline))
-static int b(int p)
-{
-  if (p<0)
-    return a(p+1);
-  return 1;
-}
-int main()
-{
-  int aa;
-  ptr = &barvar;
-  aa=!b(3);
-  ptr = 0;
-  return aa;
-}
+/* { dg-options "-O2 -fno-ipa-vrp -fdump-tree-optimized -fno-tree-ccp -fdisable-tree-evrp -fdisable-tree-vrp1 -fdisable-tree-vrp2 -fno-thread-jumps -fno-tree-dominator-opts"  } */
+
+#include "pure-const-3.h"
+
 /* { dg-final { scan-tree-dump "barvar"  "optimized"  } } */
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3.h b/gcc/testsuite/g++.dg/ipa/pure-const-3.h
new file mode 100644 (file)
index 0000000..61d162f
--- /dev/null
@@ -0,0 +1,29 @@
+int *ptr;
+static int barvar;
+static int b(int a);
+/* We can not detect A to be const because it may be interposed by unoptimized
+   body.  */
+inline
+__attribute__ ((noinline))
+int a(int a)
+{
+  if (a>0)
+    return b(a-1);
+  return *ptr == *ptr;
+}
+inline
+__attribute__ ((noinline))
+static int b(int p)
+{
+  if (p<0)
+    return a(p+1);
+  return 1;
+}
+int main()
+{
+  int aa;
+  ptr = &barvar;
+  aa=!b(3);
+  ptr = 0;
+  return aa;
+}
diff --git a/gcc/testsuite/g++.dg/ipa/pure-const-3b.C b/gcc/testsuite/g++.dg/ipa/pure-const-3b.C
new file mode 100644 (file)
index 0000000..eaa4842
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-ipa-vrp -fno-tree-ccp -fdisable-tree-evrp -fno-thread-jumps -fdump-ipa-cp-details" } */
+
+#include "pure-const-3.h"
+
+/* { dg-final { scan-ipa-dump "Propagated bits info for function int b"  "cp"  } } */