[PATCH] Fix PR59139

Richard Biener rguenther@suse.de
Mon Dec 2 15:18:00 GMT 2013


This fixes PR59139, ternary support was missing from get_val_for.
Instead of supporting it I simply chose to properly disable its
support.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2013-12-02  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/59139
	* tree-ssa-loop-niter.c (chain_of_csts_start): Properly match
	code in get_val_for.
	(get_val_for): Use gcc_checking_asserts.

	* gcc.dg/torture/pr59139.c: New testcase.

Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c	(revision 205585)
--- gcc/tree-ssa-loop-niter.c	(working copy)
*************** chain_of_csts_start (struct loop *loop,
*** 2075,2081 ****
        return NULL;
      }
  
!   if (gimple_code (stmt) != GIMPLE_ASSIGN)
      return NULL;
  
    code = gimple_assign_rhs_code (stmt);
--- 2075,2082 ----
        return NULL;
      }
  
!   if (gimple_code (stmt) != GIMPLE_ASSIGN
!       || gimple_assign_rhs_class (stmt) == GIMPLE_TERNARY_RHS)
      return NULL;
  
    code = gimple_assign_rhs_code (stmt);
*************** get_val_for (tree x, tree base)
*** 2143,2149 ****
  {
    gimple stmt;
  
!   gcc_assert (is_gimple_min_invariant (base));
  
    if (!x)
      return base;
--- 2144,2150 ----
  {
    gimple stmt;
  
!   gcc_checking_assert (is_gimple_min_invariant (base));
  
    if (!x)
      return base;
*************** get_val_for (tree x, tree base)
*** 2152,2158 ****
    if (gimple_code (stmt) == GIMPLE_PHI)
      return base;
  
!   gcc_assert (is_gimple_assign (stmt));
  
    /* STMT must be either an assignment of a single SSA name or an
       expression involving an SSA name and a constant.  Try to fold that
--- 2153,2159 ----
    if (gimple_code (stmt) == GIMPLE_PHI)
      return base;
  
!   gcc_checking_assert (is_gimple_assign (stmt));
  
    /* STMT must be either an assignment of a single SSA name or an
       expression involving an SSA name and a constant.  Try to fold that
Index: gcc/testsuite/gcc.dg/torture/pr59139.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr59139.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr59139.c	(working copy)
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do compile } */
+ 
+ int a, b, c, d, e;
+ int fn1(p1, p2) { return p2 == 0 ? p1 : 1 % p2; }
+ 
+ void fn2()
+ {
+   c = 0;
+   for (;; c = (unsigned short)c)
+     {
+       b = 2;
+       for (; b; b = a)
+ 	{
+ 	  e = fn1(2, c && 1);
+ 	  d = c == 0 ? e : c;
+ 	  if (d)
+ 	    return;
+ 	}
+     }
+ }



More information about the Gcc-patches mailing list