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]

Re: [PATCH] PR41661, fold compare in IPCP


Hi,

On Sun, Oct 11, 2009 at 05:23:53PM +0200, Richard Guenther wrote:
> On Sun, Oct 11, 2009 at 4:51 PM, Chung-Lin Tang
> <cltang@pllab.cs.nthu.edu.tw> wrote:
> > Hi,
> > this seems to be caused by using the type of the constant operand for
> > folding the binary expression in ipcp_lattice_from_jfunc(), while it should
> > actually pass the type of the whole expression. In this case for example,
> > for a compare expression of two doubles, a 'double' type is passed instead
> > of 'int'.
> >
> > The correct type to pass should be the type of the whole argument at the
> > call-site when computing the jump function, so a 'type' field was added to
> > struct ipa_pass_through_data to record this.
> >
> > Here's my proposed fix. The testcase is further simplified from the one on
> > bugzilla.
> 
> I think it's more robust to restrict the supported binary operations
> appropriately,
> namely to tcc_binary.
> 

The patch below restricts the operations for which we build polynomial
pass-through functions to tcc_comparisons and those which perform only
useless type conversions.  When building a lattice out of a
pass-through function, we handle the comparisons specially and always
request boolean type from the folder.

Nevertheless, thanks for the root cause analysis, it has certainly
saved me some time.  I have also retained the testcase (thanks for it
too) but put it into the torture directory and changed the required
flags to -fno-early-inlining.  This way it gets tested at all -O
levels (I have verified that it fails at -O3 with the current trunk).

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin


2009-10-12  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/41661
	* ipa-prop.c (compute_complex_pass_through): Allow only operations
	that are tcc_comparisons or do not change the type in any
	un-usleless way.
	* ipa-cp.c (ipcp_lattice_from_jfunc): Request boolean type when
	folding tcc_comparison operations.

	* testsuite/gcc.c-torture/compile/pr41661.c: New test.


Index: small/gcc/ipa-cp.c
===================================================================
--- small.orig/gcc/ipa-cp.c
+++ small/gcc/ipa-cp.c
@@ -299,9 +299,16 @@ ipcp_lattice_from_jfunc (struct ipa_node
       cst = caller_lat->constant;
 
       if (jfunc->value.pass_through.operation != NOP_EXPR)
-	cst = fold_binary (jfunc->value.pass_through.operation,
-			   TREE_TYPE (cst), cst,
-			   jfunc->value.pass_through.operand);
+	{
+	  tree restype;
+	  if (TREE_CODE_CLASS (jfunc->value.pass_through.operation)
+	      == tcc_comparison)
+	    restype = boolean_type_node;
+	  else
+	    restype = TREE_TYPE (cst);
+	  cst = fold_binary (jfunc->value.pass_through.operation,
+			     restype, cst, jfunc->value.pass_through.operand);
+	}
       if (!cst || !is_gimple_ip_invariant (cst))
 	lat->type = IPA_BOTTOM;
       lat->constant = cst;
Index: small/gcc/ipa-prop.c
===================================================================
--- small.orig/gcc/ipa-prop.c
+++ small/gcc/ipa-prop.c
@@ -357,6 +357,9 @@ compute_complex_pass_through (struct ipa
     {
       if (TREE_CODE (op1) != SSA_NAME
 	  || !SSA_NAME_IS_DEFAULT_DEF (op1)
+	  || (TREE_CODE_CLASS (gimple_expr_code (stmt)) != tcc_comparison
+	      && !useless_type_conversion_p (TREE_TYPE (name),
+					     TREE_TYPE (op1)))
 	  || !is_gimple_ip_invariant (op2))
 	return;
 
Index: small/gcc/testsuite/gcc.c-torture/compile/pr41661.c
===================================================================
--- /dev/null
+++ small/gcc/testsuite/gcc.c-torture/compile/pr41661.c
@@ -0,0 +1,20 @@
+/* PR tree-optimization/41661 */
+/* { dg-do compile } */
+/* { dg-options "-fno-early-inlining" } */
+
+int g;
+
+void foo (int x)
+{
+  g = x;
+}
+
+void bar (double d)
+{
+  foo (d == 1);
+}
+
+void baz (int a)
+{
+  bar (1);
+}


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