aboutsummaryrefslogtreecommitdiff
path: root/gcc/ipa-cp.c
diff options
context:
space:
mode:
authorMartin Jambor <mjambor@suse.cz>2020-06-16 19:26:32 +0200
committerMartin Jambor <mjambor@suse.cz>2020-11-23 23:52:29 +0100
commitf38a33a2745cf9f5ce1d71162185fe39fa5f3701 (patch)
tree84e69f026994401e2129fd826576f87a980b585d /gcc/ipa-cp.c
parentf80565da33598c4dbc70ea9c83272ed6bfff7a0d (diff)
downloadgcc-f38a33a2745cf9f5ce1d71162185fe39fa5f3701.zip
gcc-f38a33a2745cf9f5ce1d71162185fe39fa5f3701.tar.gz
gcc-f38a33a2745cf9f5ce1d71162185fe39fa5f3701.tar.bz2
ipa: special pass-through op for Fortran strides
when Fortran functions pass array descriptors they receive as a parameter to another function, they actually rebuild it. Thanks to work done mainly by Feng, IPA-CP can already handle the cases when they pass directly the values loaded from the original descriptor. Unfortunately, perhaps the most important one, stride, is first checked against zero and is replaced with one in that case: _12 = *a_11(D).dim[0].stride; if (_12 != 0) goto <bb 4>; [50.00%] else goto <bb 3>; [50.00%] <bb 3> // empty BB <bb 4> # iftmp.22_9 = PHI <_12(2), 1(3)> ... parm.6.dim[0].stride = iftmp.22_9; ... __x_MOD_foo (&parm.6, b_31(D)); in the most important and hopefully common cases, the incoming value is already 1 and we fail to propagate it. I would therefore like to propose the following way of encoding this situation in pass-through jump functions using using ASSERTT_EXPR operation code meaning that if the incoming value is the same as the "operand" in the jump function, it is passed on, otherwise the result is unknown. This of course captures only the single (but most important) case but is an improvement and does not need enlarging the jump function structure and is simple to pattern match. Encoding that zero needs to be changed to one would need another field and matching it would be slightly more complicated too. gcc/ 2020-06-12 Martin Jambor <mjambor@suse.cz> * ipa-prop.h (ipa_pass_through_data): Expand comment describing operation. * ipa-prop.c (analyze_agg_content_value): Detect new special case and encode it as ASSERT_EXPR. * ipa-cp.c (values_equal_for_ipcp_p): Move before ipa_get_jf_arith_result. (ipa_get_jf_arith_result): Special case ASSERT_EXPR. gcc/testsuite/ 2020-06-12 Martin Jambor <mjambor@suse.cz> * gfortran.dg/ipcp-array-2.f90: New test.
Diffstat (limited to 'gcc/ipa-cp.c')
-rw-r--r--gcc/ipa-cp.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index c3ee71e..a06b4d1 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1304,6 +1304,26 @@ initialize_node_lattices (struct cgraph_node *node)
}
}
+/* Return true iff X and Y should be considered equal values by IPA-CP. */
+
+static bool
+values_equal_for_ipcp_p (tree x, tree y)
+{
+ gcc_checking_assert (x != NULL_TREE && y != NULL_TREE);
+
+ if (x == y)
+ return true;
+
+ if (TREE_CODE (x) == ADDR_EXPR
+ && TREE_CODE (y) == ADDR_EXPR
+ && TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL
+ && TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL)
+ return operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)),
+ DECL_INITIAL (TREE_OPERAND (y, 0)), 0);
+ else
+ return operand_equal_p (x, y, 0);
+}
+
/* Return the result of a (possibly arithmetic) operation on the constant
value INPUT. OPERAND is 2nd operand for binary operation. RES_TYPE is
the type of the parameter to which the result is passed. Return
@@ -1321,6 +1341,14 @@ ipa_get_jf_arith_result (enum tree_code opcode, tree input, tree operand,
if (!is_gimple_ip_invariant (input))
return NULL_TREE;
+ if (opcode == ASSERT_EXPR)
+ {
+ if (values_equal_for_ipcp_p (input, operand))
+ return input;
+ else
+ return NULL_TREE;
+ }
+
if (!res_type)
{
if (TREE_CODE_CLASS (opcode) == tcc_comparison)
@@ -1753,26 +1781,6 @@ ipcp_verify_propagated_values (void)
}
}
-/* Return true iff X and Y should be considered equal values by IPA-CP. */
-
-static bool
-values_equal_for_ipcp_p (tree x, tree y)
-{
- gcc_checking_assert (x != NULL_TREE && y != NULL_TREE);
-
- if (x == y)
- return true;
-
- if (TREE_CODE (x) == ADDR_EXPR
- && TREE_CODE (y) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL
- && TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL)
- return operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)),
- DECL_INITIAL (TREE_OPERAND (y, 0)), 0);
- else
- return operand_equal_p (x, y, 0);
-}
-
/* Return true iff X and Y should be considered equal contexts by IPA-CP. */
static bool