https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113210

--- Comment #14 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #13)
> (In reply to Richard Biener from comment #12)
> > (In reply to Jakub Jelinek from comment #11)
> > > (In reply to Richard Biener from comment #9)
> > > > That is, another fix might be to adjust NITERSM1 to NITERS - 1 when
> > > > NITERS went constant ...  (btw, I want to get rid of _NITERS and only
> > > 
> > > Or we could only use fold_build2 for the PLUS_EXPR 1 computation if 
> > > NITERSM1
> > > is INTEGER_CST, otherwise use build2...
> > 
> > I think we should see where the original expression is built but not folded.
> 
> Hmm, probably in estimate_numbers_of_iterations,
> 
>       if (TREE_CODE (niter_desc.may_be_zero) != INTEGER_CST)
>         niter = build3 (COND_EXPR, type, niter_desc.may_be_zero,
>                         build_int_cst (type, 0),
>                         niter);
> 
> I vaguely remember code trying to pattern match the COND_EXPR created
> by this (though it should instead use number_of_iterations_exit).  It
> should be safe to replace the above with fold_build3.

No, it's not that.  The COND_EXPR is folded, but we see

(short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1 +
255) : 0

and that isn't catched.

#0  0x00000000014d3464 in fold_build3_loc (loc=0, code=COND_EXPR, 
    type=<integer_type 0x7ffff704b540 short unsigned int>, 
    op0=<gt_expr 0x7ffff7207f50>, op1=<bit_not_expr 0x7ffff6e13540>, 
    op2=<integer_cst 0x7ffff7047378>)
    at /space/rguenther/src/gcc/gcc/fold-const.cc:14174
#1  0x00000000014d0513 in fold_ternary_loc (loc=0, code=COND_EXPR, 
    type=<integer_type 0x7ffff704b540 short unsigned int>, 
    op0=<le_expr 0x7ffff7207f00>, op1=<integer_cst 0x7ffff7047378>, 
    op2=<bit_not_expr 0x7ffff6e13540>)
    at /space/rguenther/src/gcc/gcc/fold-const.cc:13238
#2  0x00000000014d3436 in fold_build3_loc (loc=0, code=COND_EXPR, 
    type=<integer_type 0x7ffff704b540 short unsigned int>, 
    op0=<le_expr 0x7ffff7207f00>, op1=<integer_cst 0x7ffff7047378>, 
    op2=<bit_not_expr 0x7ffff6e13540>)
    at /space/rguenther/src/gcc/gcc/fold-const.cc:14172
#3  0x0000000001d4de50 in vect_get_loop_niters (loop=0x7ffff71e3600, 
    main_exit=0x7ffff7203990, assumptions=0x7fffffffd200, 
    number_of_iterations=0x7fffffffd1f0, number_of_iterationsm1=0x7fffffffd1f8)
    at /space/rguenther/src/gcc/gcc/tree-vect-loop.cc:919

So I suggest to either try fixing that or, when adding one folds to a constant
make sure M1 is constant as well.

Reply via email to