fold bug with multiply and cast and conditional

Andrew Pinski pinskia@physics.uc.edu
Thu Dec 9 04:23:00 GMT 2004


I noticed this will working on my tree combiner, I don't know if I can 
reproduce it
with any front-end though.

Take the following code:
int f(int a, int *b)
{
   _Bool a1 = (a!=0);
   return a1 * 4;
}

When I do my combining I produce a tree like:
<mult_expr 0x4240f384
     type integer_type
     arg 0 <convert_expr 0x42409f20 type <integer_type 0x4241164c int>
         arg 0 <ne_expr 0x4240f360 type <boolean_type 0x42411934 _Bool>
             arg 0 <ssa_name 0x4240f45c type integer_type>
             arg 1 <integer_cst 0x42409a20 constant invariant 0>>>
     arg 1 <integer_cst 0x42409d20 type integer_type >

but we fold that to 0:
<integer_cst 0x42409a20 type <integer_type 0x4241164c int> constant 
invariant 0>

This seems wrong.

Note this bug causes a large number of regressions with my tree 
combiner enabled.

Also looking at the code it looks like we never set the variables lhs 
and rhs
for the non COND_EXPR case.

Also I think this is a regression from 3.4.x where we do the correct 
thing for
this case.
I think this was changed with the following patch:
2004-05-20  Roger Sayle  <roger@eyesopen.com>

         PR middle-end/3074
         * fold-const.c (strip_compound_expr): Delete function.
         (count_cond): Delete function.
         (fold_binary_op_with_conditional_arg): Only perform 
transformations
         "a + (b?c:d) -> b ? a+c : a+d" and "(b?c:d) + a -> b ? c+a : 
d+a"
         when a is constant.  This greatly simplifies this routine.

         * tree.c (saved_expr_p): Delete function.
         * tree.h (saved_expr_p): Delete function prototype.


Thanks,
Andrew Pinski



More information about the Gcc mailing list