This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix __builtin_constant_p handling in tree-ssa-threadedge.c (PR tree-optimization/38789)


Hi!

__builtin_constant_p needs to be handled the same way as
__builtin_object_size.  The fact that all PHI arguments are constant doesn't
mean __builtin_constant_p (x ? 1 : 2) should return true.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2009-01-16  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/38789
	* tree-ssa-threadedge.c
	(record_temporary_equivalences_from_stmts_at_dest): Ignore calls to
	__builtin_object_size.

	* gcc.c-torture/compile/pr38789.c: New test.

--- gcc/tree-ssa-threadedge.c.jj	2008-10-23 13:21:41.000000000 +0200
+++ gcc/tree-ssa-threadedge.c	2009-01-16 13:57:49.000000000 +0100
@@ -1,5 +1,5 @@
 /* SSA Jump Threading
-   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
    Contributed by Jeff Law  <law@redhat.com>
 
 This file is part of GCC.
@@ -320,12 +320,22 @@ record_temporary_equivalences_from_stmts
 
 	 The result of __builtin_object_size is defined to be the maximum of
 	 remaining bytes. If we use only one edge on the phi, the result will
-	 change to be the remaining bytes for the corresponding phi argument. */
+	 change to be the remaining bytes for the corresponding phi argument.
+
+	 Similarly for __builtin_constant_p:
+
+	 r = PHI <1(2), 2(3)>
+	 __builtin_constant_p (r)
+
+	 Both PHI arguments are constant, but x ? 1 : 2 is still not
+	 constant.  */
 
       if (is_gimple_call (stmt))
 	{
 	  tree fndecl = gimple_call_fndecl (stmt);
-	  if (fndecl && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_OBJECT_SIZE)
+	  if (fndecl
+	      && (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_OBJECT_SIZE
+		  || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CONSTANT_P))
 	    continue;
 	}
 
--- gcc/testsuite/gcc.c-torture/compile/pr38789.c.jj	2009-01-16 14:03:29.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr38789.c	2009-01-16 14:01:52.000000000 +0100
@@ -0,0 +1,18 @@
+/* PR tree-optimization/38789 */
+
+void
+baz (int v)
+{
+  unsigned a = (v == 1) ? 1 : 2;
+
+  if (__builtin_constant_p (a))
+    asm volatile ("# constant %0" :: "i" (a));
+  else
+    asm volatile ("# register %0" :: "r" (a));
+
+  a = 6;
+  if (__builtin_constant_p (a))
+    asm volatile ("# constant %0" :: "i" (a));
+  else
+    asm volatile ("# register %0" :: "r" (a));
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]