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 PR33992, profiledbootstrap miscompile


This fixes the testcase in PR33992 where we forgot to update the
type of a zero used in a comparison.  Thus forwprop came along and
used this (wrong) type to truncante a constant.  whoops.

Fixed thusly, bootstrapped and tested on x86_64-unknown-linux-gnu, applied
to mainline.

Credits go to Uros for reducing the testcase.

Richard.

2008-02-10  Uros Bizjak  <ubizjak@gmail.com>
	Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/33992
	* tree-ssa-loop-im.c (rewrite_bittest): Fixup the type of
	the zero we compare against.

	* gcc.c-torture/execute/pr33992.c: New testcase.

Index: tree-ssa-loop-im.c
===================================================================
*** tree-ssa-loop-im.c	(revision 132221)
--- tree-ssa-loop-im.c	(working copy)
*************** rewrite_bittest (block_stmt_iterator *bs
*** 685,691 ****
--- 685,696 ----
        stmt2 = build_gimple_modify_stmt (var, t);
        name = make_ssa_name (var, stmt2);
        GIMPLE_STMT_OPERAND (stmt2, 0) = name;
+ 
+       /* Replace the SSA_NAME we compare against zero.  Adjust
+ 	 the type of zero accordingly.  */
        SET_USE (use, name);
+       TREE_OPERAND (COND_EXPR_COND (use_stmt), 1)
+ 	= build_int_cst_type (TREE_TYPE (name), 0);
  
        bsi_insert_before (bsi, stmt1, BSI_SAME_STMT);
        bsi_replace (bsi, stmt2, true);
Index: testsuite/gcc.c-torture/execute/pr33992.c
===================================================================
*** testsuite/gcc.c-torture/execute/pr33992.c	(revision 0)
--- testsuite/gcc.c-torture/execute/pr33992.c	(revision 0)
***************
*** 0 ****
--- 1,38 ----
+ extern void abort ();
+ 
+ void __attribute__((noinline))
+ bar (unsigned long long i)
+ {
+   if (i)
+     abort ();
+ }
+ 
+ void __attribute__((always_inline))
+ foo (unsigned long long *r)
+ 
+ {
+   int i;
+ 
+   for (i = 0; ; i++)
+     if (*r & ((unsigned long long)1 << (63 - i)))
+       break;
+ 
+   bar (i);
+ }
+ 
+ void __attribute__((noinline))
+ do_test (unsigned long long *r)
+ {
+   int i;
+ 
+   for (i = 0; i < 2; ++i)
+     foo (r);
+ }
+ 
+ int main()
+ {
+   unsigned long long r = 0x8000000000000001ull;
+ 
+   do_test (&r);
+   return 0;
+ }


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