aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-phiopt.c
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2021-06-12 19:14:46 -0700
committerAndrew Pinski <apinski@marvell.com>2021-07-05 12:44:14 -0700
commita50cecb20a10a729b3f5f157b154d28f9937a652 (patch)
tree1c0d92be5b25278adf2b9f15f30a4f1dd89a6ca6 /gcc/tree-ssa-phiopt.c
parentcd48e550d1dc58307ab1c0ab490745673f748ccc (diff)
downloadgcc-a50cecb20a10a729b3f5f157b154d28f9937a652.zip
gcc-a50cecb20a10a729b3f5f157b154d28f9937a652.tar.gz
gcc-a50cecb20a10a729b3f5f157b154d28f9937a652.tar.bz2
Try inverted comparison for match_simplify in phiopt
Since match and simplify does not have all of the inverted comparison patterns, it make sense to just have phi-opt try to do the inversion and try match and simplify again. OK? Bootstrapped and tested on x86_64-linux-gnu. Thanks, Andrew Pinski gcc/ChangeLog: * tree-ssa-phiopt.c (gimple_simplify_phiopt): If "A ? B : C" fails to simplify, try "(!A) ? C : B".
Diffstat (limited to 'gcc/tree-ssa-phiopt.c')
-rw-r--r--gcc/tree-ssa-phiopt.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 17bc597..f8d7ae1 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -836,7 +836,8 @@ phiopt_early_allow (enum tree_code code)
with parts pushed if EARLY_P was true. Also rejects non allowed tree code
if EARLY_P is set.
Takes the comparison from COMP_STMT and two args, ARG0 and ARG1 and tries
- to simplify CMP ? ARG0 : ARG1. */
+ to simplify CMP ? ARG0 : ARG1.
+ Also try to simplify (!CMP) ? ARG1 : ARG0 if the non-inverse failed. */
static tree
gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt,
tree arg0, tree arg1,
@@ -869,6 +870,30 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt,
return result;
}
}
+ /* Try the inverted comparison, that is !COMP ? ARG1 : ARG0. */
+ comp_code = invert_tree_comparison (comp_code, HONOR_NANS (cmp0));
+
+ if (comp_code == ERROR_MARK)
+ return NULL;
+
+ cond = build2_loc (loc,
+ comp_code, boolean_type_node,
+ cmp0, cmp1);
+ gimple_match_op op1 (gimple_match_cond::UNCOND,
+ COND_EXPR, type, cond, arg1, arg0);
+
+ if (op1.resimplify (early_p ? NULL : seq, follow_all_ssa_edges))
+ {
+ /* Early we want only to allow some generated tree codes. */
+ if (!early_p
+ || op1.code.is_tree_code ()
+ || phiopt_early_allow ((tree_code)op1.code))
+ {
+ result = maybe_push_res_to_seq (&op1, seq);
+ if (result)
+ return result;
+ }
+ }
return NULL;
}