[PATCH] Fix PR36978, ICE with loop unswitching

Richard Guenther rguenther@suse.de
Thu Jul 31 16:54:00 GMT 2008


When building a gimple_cond from a tree we get mildly confused by
extra casts that fold inserts due to it following stricter type
rules than the middle-end.  In this particular case though there
is no reason to fold the tree if the condition is extracted from
a gimple_cond in the first place.

Thus the following simple fix.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

2008-07-31  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/36978
	* tree-ssa-loop-unswitch.c (tree_may_unswitch_on): Do not fold
	the generated condition.

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

Index: gcc/tree-ssa-loop-unswitch.c
===================================================================
*** gcc/tree-ssa-loop-unswitch.c	(revision 138374)
--- gcc/tree-ssa-loop-unswitch.c	(working copy)
*************** tree_may_unswitch_on (basic_block bb, st
*** 123,130 ****
  	return NULL_TREE;
      }
  
!   cond = fold_build2 (gimple_cond_code (stmt), boolean_type_node,
! 		      gimple_cond_lhs (stmt), gimple_cond_rhs (stmt));
  
    /* To keep the things simple, we do not directly remove the conditions,
       but just replace tests with 0/1.  Prevent the infinite loop where we
--- 123,130 ----
  	return NULL_TREE;
      }
  
!   cond = build2 (gimple_cond_code (stmt), boolean_type_node,
! 		 gimple_cond_lhs (stmt), gimple_cond_rhs (stmt));
  
    /* To keep the things simple, we do not directly remove the conditions,
       but just replace tests with 0/1.  Prevent the infinite loop where we
Index: gcc/testsuite/gcc.dg/torture/pr36978.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr36978.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr36978.c	(revision 0)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do compile } */
+ /* { dg-options "-funswitch-loops" } */
+ 
+ unsigned short status;
+ void foo (const _Bool flag)
+ {
+   if (status == 2 || status == 7)
+     {
+       while (status != 2 && (status != 7 || !flag))
+ 	{
+ 	}
+     }
+ }
+ 



More information about the Gcc-patches mailing list