Bug 28162 - [4.2 Regression] ICE in set_value_range, at tree-vrp.c:157
Summary: [4.2 Regression] ICE in set_value_range, at tree-vrp.c:157
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Richard Biener
URL:
Keywords: ice-checking, ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2006-06-25 09:26 UTC by David Binderman
Modified: 2006-07-05 15:49 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-06-25 12:02:00


Attachments
C source code (89.38 KB, application/octet-stream)
2006-06-25 09:28 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2006-06-25 09:26:35 UTC
I just tried to compile the attached source code with compiler flag -O3.
GNU C compiler version 4.2 snapshot 20060624 said

dcb@linux:~/gnu/42-20060617/bugs> ~/gnu/42-20060624/results/bin/gcc -O3 bug18.c
bug18.c: In function 'Speech_Encode_Frame_init':
bug18.c:24528: warning: passing argument 1 of 'Speech_Encode_Frame_exit' from incompatible pointer type
bug18.c: In function 'ol_ltp':
bug18.c:19118: internal compiler error: in set_value_range, at tree-vrp.c:157
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
dcb@linux:~/gnu/42-20060624/bugs>

Preprocessed source code attached.  Flag -O3 required.
Comment 1 David Binderman 2006-06-25 09:28:17 UTC
Created attachment 11744 [details]
C source code
Comment 2 Richard Biener 2006-06-25 10:01:39 UTC
min is not less than max:

(gdb) call debug_tree (min)
 <integer_cst 0xa78f57b0 type <integer_type 0xa7bf42e0 unsigned int> constant invariant 4294966724>
(gdb) call debug_tree (max)
 <integer_cst 0xa7be2498 type <integer_type 0xa7bf433c long int> constant invariant 2147483647>

but worse, their types don't match.  (I guess the former wants to be casted
to int)

#1  0x086124ff in set_value_range (vr=0xaff5a110, t=VR_RANGE, min=0xa78f57b0,
    max=0xa7be2498, equiv=0x8a30dd8)
    at /home/richard/src/trunk/gcc/tree-vrp.c:157
#2  0x08617d92 in adjust_range_with_scev (vr=0xaff5a110, loop=0x89f3980,
    stmt=0xa7966774, var=0xa700a1e0)
    at /home/richard/src/trunk/gcc/tree-vrp.c:2090
#3  0x0861e035 in vrp_visit_assignment (stmt=0xa7966774, output_p=0xaff5a278)
    at /home/richard/src/trunk/gcc/tree-vrp.c:3457
#4  0x0861f9a0 in vrp_visit_stmt (stmt=0xa7966774, taken_edge_p=0xaff5a27c,
    output_p=0xaff5a278) at /home/richard/src/trunk/gcc/tree-vrp.c:3850

(gdb) call debug_generic_expr (stmt)
D.23941_257 = p_max1D.23874_118 * 0fffffffc
 <mult_expr 0xa7966798
    type <integer_type 0xa7bf42e0 unsigned int public unsigned SI
        size <integer_cst 0xa7be23f0 constant invariant 32>
        unit size <integer_cst 0xa7be2180 constant invariant 4>
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xa7be2468 0> max <integer_cst 0xa7be2450 4294967295>
        pointer_to_this <pointer_type 0xa7c94e60>>

    arg 0 <ssa_name 0xa7566e40
        type <integer_type 0xa7a5bcf0 Word32 sizes-gimplified public SI size <integer_cst 0xa7be23f0 32> unit size <integer_cst 0xa7be2180 4>
            align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xa7be2480 -2147483648> max <integer_cst 0xa7be2498 2147483647>
            pointer_to_this <pointer_type 0xa7a60678>>
        var <var_decl 0xa7897898 p_max1> def_stmt <modify_expr 0xa794fbf4>
        version 118>
    arg 1 <integer_cst 0xa79a1be8 type <integer_type 0xa7bf42e0 unsigned int> constant invariant 4294967292>>

type mismatch in the MULT_EXPR (signed vs. unsigned).

ol_ltpD.6288::

;; basic block 10, loop depth 1, count 0
;; prev block 17, next block 11
;; pred:       67 (true,exec)
;; succ:       11 (true) 12 (false)
<L24>:;
p_max1_118 = ASSERT_EXPR <p_max1_13, p_max1_13 > 19>;
D.23941_257 = p_max1_118 * 0fffffffc;
D.23942_258 = (Float32 *) D.23941_257;
D.23943_259 = D.23942_258 + &corr[143];
...
Comment 3 Richard Biener 2006-06-25 10:30:15 UTC
Reduced testcase, still needs -O3 (and checking enabled):

void Lag_max_wght(float corr[], long wght_flg)
{
     float t0, max;
     const float *ww;
     long i;
     if ( wght_flg > 0 ) {
        for ( i = 143; i >= 20; i-- ) {
           t0 = corr[ - i] * *ww--;
           if ( t0 >= max )
             max = t0;
        }
     }
}
Comment 4 Richard Biener 2006-06-25 12:02:00 UTC
.003.original is already wrong:

t0 = *((float *) (i * 0fffffffc) + corr) * (float) *ww-- ;

we ask fold to fold (unsigned)-i * 4U

which continues to ask fold to fold i * -4U (buggy already), which is from

    case MULT_EXPR:
      /* (-A) * (-B) -> A * B  */
      if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
        return fold_build2 (MULT_EXPR, type,
                            TREE_OPERAND (arg0, 0),
                            negate_expr (arg1));

it should use fold_convert () on the args.  The following fixes it:

Index: fold-const.c
===================================================================
--- fold-const.c        (revision 114974)
+++ fold-const.c        (working copy)
@@ -8866,12 +8866,12 @@ fold_binary (enum tree_code code, tree t
       /* (-A) * (-B) -> A * B  */
       if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
        return fold_build2 (MULT_EXPR, type,
-                           TREE_OPERAND (arg0, 0),
-                           negate_expr (arg1));
+                           fold_convert (type, TREE_OPERAND (arg0, 0)),
+                           fold_convert (type, negate_expr (arg1)));
       if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
        return fold_build2 (MULT_EXPR, type,
-                           negate_expr (arg0),
-                           TREE_OPERAND (arg1, 0));
+                           fold_convert (type, negate_expr (arg0)),
+                           fold_convert (type, TREE_OPERAND (arg1, 0)));

       if (! FLOAT_TYPE_P (type))
        {

(obvious, but has to wait until after the summit.)
Comment 5 patchapp@dberlin.org 2006-07-05 10:45:19 UTC
Subject: Bug number PR28162

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-07/msg00133.html
Comment 6 Richard Biener 2006-07-05 15:49:26 UTC
Subject: Bug 28162

Author: rguenth
Date: Wed Jul  5 15:49:12 2006
New Revision: 115202

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115202
Log:
2006-07-05  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/28162
	* fold-const.c (fold_binary): For (-A) * (-B) -> A * B
	make sure to convert the operands to the correct type.

	* gcc.dg/pr28162.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/pr28162.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Richard Biener 2006-07-05 15:49:57 UTC
Fixed.  Modulo the problem being latent on 4.1.
Comment 8 Richard Biener 2006-07-11 13:57:13 UTC
Subject: Bug 28162

Author: rguenth
Date: Tue Jul 11 13:57:05 2006
New Revision: 115333

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115333
Log:
2006-07-11  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/28162
	* fold-const.c (fold_binary): For (-A) * (-B) -> A * B
	make sure to convert the operands to the correct type.

	* gcc.dg/pr28162.c: New testcase.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/pr28162.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/fold-const.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog