aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-12-06 10:58:10 +0100
committerJakub Jelinek <jakub@redhat.com>2020-12-06 10:58:10 +0100
commit8c23434fdadcf4caa1f0e966294c5f67ccf4bcf9 (patch)
treeab85825958107ecc849c9da1e95a51d2670a545d /gcc
parent9e12b8b1819342ef7efac58cf7f4ba4294abe551 (diff)
downloadgcc-8c23434fdadcf4caa1f0e966294c5f67ccf4bcf9.zip
gcc-8c23434fdadcf4caa1f0e966294c5f67ccf4bcf9.tar.gz
gcc-8c23434fdadcf4caa1f0e966294c5f67ccf4bcf9.tar.bz2
[PATCH] phiopt: Handle bool in two_value_replacement [PR796232]
The following patch improves code generation on the included testcase by enabling two_value_replacement on booleans. It does that only for arg0/arg1 values that conditional_replacement doesn't handle. Additionally it limits two_value_replacement optimization to the late phiopt like conditional_replacement. 2020-12-06 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/96232 * tree-ssa-phiopt.c (two_value_replacement): Optimize even boolean lhs cases as long as arg0 has wider precision and conditional_replacement doesn't handle that case. (tree_ssa_phiopt_worker): Don't call two_value_replacement during early phiopt. * gcc.dg/tree-ssa/pr96232-2.c: New test. * gcc.dg/tree-ssa/pr88676-2.c: Check phiopt2 dump rather than phiopt1.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr88676-2.c4
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr96232-2.c18
-rw-r--r--gcc/tree-ssa-phiopt.c23
3 files changed, 39 insertions, 6 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr88676-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr88676-2.c
index 0e61636..ea88407 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr88676-2.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr88676-2.c
@@ -1,7 +1,7 @@
/* PR tree-optimization/88676 */
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt1" } */
-/* { dg-final { scan-tree-dump-not " = PHI <" "phiopt1" { target le } } } */
+/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-final { scan-tree-dump-not " = PHI <" "phiopt2" { target le } } } */
struct foo1 {
int i:1;
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96232-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr96232-2.c
new file mode 100644
index 0000000..9f51820
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96232-2.c
@@ -0,0 +1,18 @@
+/* PR tree-optimization/96232 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump " 38 - " "optimized" } } */
+/* { dg-final { scan-tree-dump " \\+ 97;" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "PHI <" "optimized" } } */
+
+int
+foo (_Bool x)
+{
+ return x ? 37 : 38;
+}
+
+int
+bar (_Bool x)
+{
+ return x ? 98 : 97;
+}
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index e2758b2..21b88c0 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -337,7 +337,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_hoist_loads, bool early_p)
}
/* Do the replacement of conditional if it can be done. */
- if (two_value_replacement (bb, bb1, e2, phi, arg0, arg1))
+ if (!early_p && two_value_replacement (bb, bb1, e2, phi, arg0, arg1))
cfgchanged = true;
else if (!early_p
&& conditional_replacement (bb, bb1, e1, e2, phi,
@@ -635,7 +635,6 @@ two_value_replacement (basic_block cond_bb, basic_block middle_bb,
if (TREE_CODE (lhs) != SSA_NAME
|| !INTEGRAL_TYPE_P (TREE_TYPE (lhs))
- || TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
|| TREE_CODE (rhs) != INTEGER_CST)
return false;
@@ -648,9 +647,25 @@ two_value_replacement (basic_block cond_bb, basic_block middle_bb,
return false;
}
+ /* Defer boolean x ? 0 : {1,-1} or x ? {1,-1} : 0 to
+ conditional_replacement. */
+ if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
+ && (integer_zerop (arg0)
+ || integer_zerop (arg1)
+ || TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE
+ || (TYPE_PRECISION (TREE_TYPE (arg0))
+ <= TYPE_PRECISION (TREE_TYPE (lhs)))))
+ return false;
+
wide_int min, max;
- if (get_range_info (lhs, &min, &max) != VR_RANGE
- || min + 1 != max
+ if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE)
+ {
+ min = wi::to_wide (boolean_false_node);
+ max = wi::to_wide (boolean_true_node);
+ }
+ else if (get_range_info (lhs, &min, &max) != VR_RANGE)
+ return false;
+ if (min + 1 != max
|| (wi::to_wide (rhs) != min
&& wi::to_wide (rhs) != max))
return false;