Bug 32681 - ice for legal C code with flags -ffast-math -O3 -ftree-vectorize
Summary: ice for legal C code with flags -ffast-math -O3 -ftree-vectorize
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.1.3
Assignee: Uroš Bizjak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-08 21:14 UTC by David Binderman
Modified: 2007-07-09 13:36 UTC (History)
2 users (show)

See Also:
Host: x86_ 64-suse-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-09 10:23:28


Attachments
C source code (11.49 KB, text/plain)
2007-07-08 21:15 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2007-07-08 21:14:18 UTC
I just tried to compile Suse Linux package aalib-1.4.0-364 with the
GNU C compiler version 4.3 snapshot 20070706

The compiler said

aarender.c: In function 'aa_renderpalette':
aarender.c:33: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Here is some help from valgrind

==21796== Invalid read of size 2
==21796==    at 0x7CE295: extract_range_from_binary_expr (tree-vrp.c:1738)
==21796==    by 0x7CF7DA: extract_range_from_expr (tree-vrp.c:2594)
==21796==    by 0x7D1572: vrp_visit_assignment (tree-vrp.c:4679)
==21796==    by 0x7D2606: vrp_visit_stmt (tree-vrp.c:5215)
==21796==    by 0x7807F1: simulate_stmt (tree-ssa-propagate.c:322)
==21796==    by 0x78113F: ssa_propagate (tree-ssa-propagate.c:445)
==21796==    by 0x7C7BFD: execute_vrp (tree-vrp.c:6100)
==21796==    by 0x61A7C8: execute_one_pass (passes.c:1126)
==21796==    by 0x61A99F: execute_pass_list (passes.c:1179)
==21796==    by 0x61A9B4: execute_pass_list (passes.c:1180)
==21796==    by 0x6EA3E7: tree_rest_of_compilation (tree-optimize.c:406)
==21796==    by 0x83F95F: cgraph_expand_function (cgraphunit.c:1073)
==21796==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

Preprocessed source code attached. Flags -ffast-math  -O3 -ftree-vectorize
required.
Comment 1 David Binderman 2007-07-08 21:15:10 UTC
Created attachment 13872 [details]
C source code
Comment 2 Ira Rosen 2007-07-09 06:22:52 UTC
I guess it's an if-cvt problem - nothing gets vectorized (and I also disabled the vectorizer to be sure), and if-cvt is applied on function aa_renderpalette (where it ICEs later).

Ira
Comment 3 Richard Biener 2007-07-09 10:00:34 UTC
It builds a TRUTH_AND_EXPR with second operand NULL_TREE ... in

#1  0x00000000008a3d96 in find_phi_replacement_condition (loop=0x2ac838a04320, 
    bb=0x2ac8389a7480, cond=0x7fff72b2f308, bsi=0x7fff72b2f2f0)
    at /space/rguenther/src/svn/pointer_plus/gcc/tree-if-conv.c:753
753             *cond = build2 (TRUTH_AND_EXPR, boolean_type_node,
754                             *cond, first_edge->aux);

where first_edge->aux is NULL.
Comment 4 Uroš Bizjak 2007-07-09 10:15:24 UTC
(In reply to comment #3)

> where first_edge->aux is NULL.

Looking into it.

Reduced testcase is:

--cut here--
int aa_renderpalette (int p)
{
  int y = 42;
  int i;

  for (i = 0; i < 256; i++)
    {
      if (y > 255)
	y = 255;
      if (y < 0)
	y = 0;

      if (p)
	y = (y < p ? 0 : (y > p) * 255 / (255 - 2 * p));
    }
    return y;
}
--cut here--

Comment 5 Uroš Bizjak 2007-07-09 10:23:28 UTC
It's a copy'n'pasto. Attached patch fixes the failure:

Index: tree-if-conv.c
===================================================================
--- tree-if-conv.c      (revision 126478)
+++ tree-if-conv.c      (working copy)
@@ -751,7 +751,7 @@ find_phi_replacement_condition (struct l
         AND it with the incoming bb predicate.  */
       if (second_edge->aux)
        *cond = build2 (TRUTH_AND_EXPR, boolean_type_node,
-                       *cond, first_edge->aux);
+                       *cond, second_edge->aux);
 
       if (TREE_CODE (*cond) == TRUTH_NOT_EXPR)
        /* We can be smart here and choose inverted
Comment 6 uros 2007-07-09 13:00:32 UTC
Subject: Bug 32681

Author: uros
Date: Mon Jul  9 13:00:19 2007
New Revision: 126482

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126482
Log:
	PR tree-optimization/32681
	* tree-if-conv.c (find_phi_replacement_condition): Use the condition
	saved in second_edge->aux when first_bb is a loop header.

testsuite/ChangeLog:

	PR tree-optimization/32681
	* gcc.dg/tree-ssa/pr32681.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr32681.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-if-conv.c

Comment 7 uros 2007-07-09 13:11:35 UTC
Subject: Bug 32681

Author: uros
Date: Mon Jul  9 13:11:22 2007
New Revision: 126483

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126483
Log:
	PR tree-optimization/32681
	* tree-if-conv.c (find_phi_replacement_condition): Use the condition
	saved in second_edge->aux when first_bb is a loop header.


Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/tree-if-conv.c

Comment 8 uros 2007-07-09 13:32:02 UTC
Subject: Bug 32681

Author: uros
Date: Mon Jul  9 13:31:46 2007
New Revision: 126484

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126484
Log:
	PR tree-optimization/32681
	* tree-if-conv.c (find_phi_replacement_condition): Use the condition
	saved in second_edge->aux when first_bb is a loop header.


Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/tree-if-conv.c

Comment 9 Uroš Bizjak 2007-07-09 13:36:25 UTC
Fixed.