This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] fix builtin-ctype-N.c
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 6 May 2004 09:46:22 -0700
- Subject: [tree-ssa] fix builtin-ctype-N.c
Two related changes here in order to see past the code generated by
__builtin_isascii. First, simplifying X^X -> 0. Second, generating
(x < y ? true : false) from (x < y) is just silly.
The later change obviates a phiopt1 test. We get the same resulting
code, but since we're not being silly from the start, there's nothing
for phiopt1 to clean up.
r~
* fold-const.c (fold): Don't build COND_EXPR from comparisons for
boolean and integer result types. Handle X ^ X for TRUTH_XOR_EXPR.
* gcc.dg/tree-ssa/20040210-1.c: Tweak scan pattern to look for ifs.
Index: gcc/fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.89
diff -c -p -d -u -r1.213.2.89 fold-const.c
--- gcc/fold-const.c 5 May 2004 17:14:19 -0000 1.213.2.89
+++ gcc/fold-const.c 6 May 2004 00:48:21 -0000
@@ -5593,9 +5593,18 @@ fold (tree expr)
return tem;
}
else if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
- return fold (build (COND_EXPR, type, arg0,
- fold (build1 (code, type, integer_one_node)),
- fold (build1 (code, type, integer_zero_node))));
+ {
+ if (TREE_CODE (type) == BOOLEAN_TYPE)
+ {
+ arg0 = copy_node (arg0);
+ TREE_TYPE (arg0) = type;
+ return arg0;
+ }
+ else if (TREE_CODE (type) != INTEGER_TYPE)
+ return fold (build (COND_EXPR, type, arg0,
+ fold (build1 (code, type, integer_one_node)),
+ fold (build1 (code, type, integer_zero_node))));
+ }
}
else if (TREE_CODE_CLASS (code) == '<'
&& TREE_CODE (arg0) == COMPOUND_EXPR)
@@ -7166,6 +7175,9 @@ fold (tree expr)
return non_lvalue (fold_convert (type, invert_truthvalue (arg1)));
if (integer_onep (arg1))
return non_lvalue (fold_convert (type, invert_truthvalue (arg0)));
+ /* Identical arguments cancel to zero. */
+ if (operand_equal_p (arg0, arg1, 0))
+ return omit_one_operand (type, integer_zero_node, arg0);
return t;
case EQ_EXPR:
Index: gcc/testsuite/gcc.dg/tree-ssa/20040210-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/tree-ssa/Attic/20040210-1.c,v
retrieving revision 1.1.2.1
diff -c -p -d -u -r1.1.2.1 20040210-1.c
--- gcc/testsuite/gcc.dg/tree-ssa/20040210-1.c 11 Feb 2004 14:55:38 -0000 1.1.2.1
+++ gcc/testsuite/gcc.dg/tree-ssa/20040210-1.c 6 May 2004 00:48:21 -0000
@@ -28,5 +28,5 @@ main(){
exit (0);
}
-/* We should convert two COND_EXPRs into straightline code. */
-/* { dg-final { scan-tree-dump-times "straightline" 2 "phiopt1"} } */
+/* Should have no more than two ifs left after straightening. */
+/* { dg-final { scan-tree-dump-times "if " 2 "phiopt1"} } */