[Bug tree-optimization/83253] -ftree-slsr causes performance regression

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 12 22:55:00 GMT 2017


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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Bill Schmidt from comment #5)
> Here's an untested patch (bootstraps successfully but regtest is still
> ongoing):
> 
> Index: gcc/gimple-ssa-strength-reduction.c                                  
> 
> ===================================================================
> --- gcc/gimple-ssa-strength-reduction.c (revision 255588)                   
> 
> +++ gcc/gimple-ssa-strength-reduction.c (working copy)                      
> 
> @@ -3083,7 +3083,17 @@ analyze_increments (slsr_cand_t first_dep, machine
>        else if (first_dep->kind == CAND_MULT)                               
> 
>         {                                                                   
> 
>           int cost = mult_by_coeff_cost (incr, mode, speed);                
> 
> -         int repl_savings = mul_cost (speed, mode) - add_cost (speed,
> mode);   
> +         int repl_savings;                                                 
> 
> +                                                                           
> 
> +         if (TREE_CODE (first_dep->stride) == INTEGER_CST)                 

Please use if (tree_fits_shwi_p (first_dep->stride)) instead, otherwise
tree_to_shwi will ICE if some stride is outside of the shwi range.

> 
> +           {                                                               
> 
> +             HOST_WIDE_INT hwi_stride = tree_to_shwi (first_dep->stride);  
> 
> +             repl_savings = (mult_by_coeff_cost (hwi_stride, mode, speed)  
> 
> +                             - add_cost (speed, mode));                    
> 
> +           }                                                               
> 
> +         else                                                              
> 
> +           repl_savings = mul_cost (speed, mode) - add_cost (speed, mode); 

Also, I think it might be better to move the - add_cost (speed, mode)
part outside of the conditional, i.e. set either repl_savings or some other
temporary just to mult_by_coeff_cost or mul_cost and then compute repl_saving
by subtracting that and add_cost.


More information about the Gcc-bugs mailing list