@@ -2089,104 +2089,104 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump)
20892089 tree target_type = TREE_TYPE (gimple_assign_lhs (c -> cand_stmt ));
20902090 enum tree_code cand_code = gimple_assign_rhs_code (c -> cand_stmt );
20912091
2092- /* It is highly unlikely, but possible, that the resulting
2093- bump doesn't fit in a HWI. Abandon the replacement
2094- in this case. This does not affect siblings or dependents
2095- of C. Restriction to signed HWI is conservative for unsigned
2096- types but allows for safe negation without twisted logic. */
2097- if (wi ::fits_shwi_p (bump )
2098- && bump .to_shwi () != HOST_WIDE_INT_MIN
2099- /* It is not useful to replace casts, copies, negates, or adds of
2100- an SSA name and a constant. */
2101- && cand_code != SSA_NAME
2102- && !CONVERT_EXPR_CODE_P (cand_code )
2103- && cand_code != PLUS_EXPR
2104- && cand_code != POINTER_PLUS_EXPR
2105- && cand_code != MINUS_EXPR
2106- && cand_code != NEGATE_EXPR )
2107- {
2108- enum tree_code code = PLUS_EXPR ;
2109- tree bump_tree ;
2110- gimple * stmt_to_print = NULL ;
2092+ /* It is not useful to replace casts, copies, negates, or adds of
2093+ an SSA name and a constant. */
2094+ if (cand_code == SSA_NAME
2095+ || CONVERT_EXPR_CODE_P (cand_code )
2096+ || cand_code == PLUS_EXPR
2097+ || cand_code == POINTER_PLUS_EXPR
2098+ || cand_code == MINUS_EXPR
2099+ || cand_code == NEGATE_EXPR )
2100+ return ;
21112101
2112- /* If the basis name and the candidate's LHS have incompatible
2113- types, introduce a cast. */
2114- if (!useless_type_conversion_p (target_type , TREE_TYPE (basis_name )))
2115- basis_name = introduce_cast_before_cand (c , target_type , basis_name );
2116- if (wi ::neg_p (bump ))
2117- {
2118- code = MINUS_EXPR ;
2119- bump = - bump ;
2120- }
2102+ enum tree_code code = PLUS_EXPR ;
2103+ tree bump_tree ;
2104+ gimple * stmt_to_print = NULL ;
21212105
2122- bump_tree = wide_int_to_tree (target_type , bump );
2106+ if (wi ::neg_p (bump ))
2107+ {
2108+ code = MINUS_EXPR ;
2109+ bump = - bump ;
2110+ }
2111+
2112+ /* It is possible that the resulting bump doesn't fit in target_type.
2113+ Abandon the replacement in this case. This does not affect
2114+ siblings or dependents of C. */
2115+ if (bump != wi ::ext (bump , TYPE_PRECISION (target_type ),
2116+ TYPE_SIGN (target_type )))
2117+ return ;
2118+
2119+ bump_tree = wide_int_to_tree (target_type , bump );
2120+
2121+ /* If the basis name and the candidate's LHS have incompatible types,
2122+ introduce a cast. */
2123+ if (!useless_type_conversion_p (target_type , TREE_TYPE (basis_name )))
2124+ basis_name = introduce_cast_before_cand (c , target_type , basis_name );
2125+
2126+ if (dump_file && (dump_flags & TDF_DETAILS ))
2127+ {
2128+ fputs ("Replacing: " , dump_file );
2129+ print_gimple_stmt (dump_file , c -> cand_stmt , 0 );
2130+ }
21232131
2132+ if (bump == 0 )
2133+ {
2134+ tree lhs = gimple_assign_lhs (c -> cand_stmt );
2135+ gassign * copy_stmt = gimple_build_assign (lhs , basis_name );
2136+ gimple_stmt_iterator gsi = gsi_for_stmt (c -> cand_stmt );
2137+ slsr_cand_t cc = c ;
2138+ gimple_set_location (copy_stmt , gimple_location (c -> cand_stmt ));
2139+ gsi_replace (& gsi , copy_stmt , false);
2140+ c -> cand_stmt = copy_stmt ;
2141+ while (cc -> next_interp )
2142+ {
2143+ cc = lookup_cand (cc -> next_interp );
2144+ cc -> cand_stmt = copy_stmt ;
2145+ }
21242146 if (dump_file && (dump_flags & TDF_DETAILS ))
2147+ stmt_to_print = copy_stmt ;
2148+ }
2149+ else
2150+ {
2151+ tree rhs1 , rhs2 ;
2152+ if (cand_code != NEGATE_EXPR ) {
2153+ rhs1 = gimple_assign_rhs1 (c -> cand_stmt );
2154+ rhs2 = gimple_assign_rhs2 (c -> cand_stmt );
2155+ }
2156+ if (cand_code != NEGATE_EXPR
2157+ && ((operand_equal_p (rhs1 , basis_name , 0 )
2158+ && operand_equal_p (rhs2 , bump_tree , 0 ))
2159+ || (operand_equal_p (rhs1 , bump_tree , 0 )
2160+ && operand_equal_p (rhs2 , basis_name , 0 ))))
21252161 {
2126- fputs ("Replacing: " , dump_file );
2127- print_gimple_stmt (dump_file , c -> cand_stmt , 0 );
2162+ if (dump_file && (dump_flags & TDF_DETAILS ))
2163+ {
2164+ fputs ("(duplicate, not actually replacing)" , dump_file );
2165+ stmt_to_print = c -> cand_stmt ;
2166+ }
21282167 }
2129-
2130- if (bump == 0 )
2168+ else
21312169 {
2132- tree lhs = gimple_assign_lhs (c -> cand_stmt );
2133- gassign * copy_stmt = gimple_build_assign (lhs , basis_name );
21342170 gimple_stmt_iterator gsi = gsi_for_stmt (c -> cand_stmt );
21352171 slsr_cand_t cc = c ;
2136- gimple_set_location ( copy_stmt , gimple_location ( c -> cand_stmt ) );
2137- gsi_replace ( & gsi , copy_stmt , false );
2138- c -> cand_stmt = copy_stmt ;
2172+ gimple_assign_set_rhs_with_ops ( & gsi , code , basis_name , bump_tree );
2173+ update_stmt ( gsi_stmt ( gsi ) );
2174+ c -> cand_stmt = gsi_stmt ( gsi ) ;
21392175 while (cc -> next_interp )
21402176 {
21412177 cc = lookup_cand (cc -> next_interp );
2142- cc -> cand_stmt = copy_stmt ;
2178+ cc -> cand_stmt = gsi_stmt ( gsi ) ;
21432179 }
21442180 if (dump_file && (dump_flags & TDF_DETAILS ))
2145- stmt_to_print = copy_stmt ;
2146- }
2147- else
2148- {
2149- tree rhs1 , rhs2 ;
2150- if (cand_code != NEGATE_EXPR ) {
2151- rhs1 = gimple_assign_rhs1 (c -> cand_stmt );
2152- rhs2 = gimple_assign_rhs2 (c -> cand_stmt );
2153- }
2154- if (cand_code != NEGATE_EXPR
2155- && ((operand_equal_p (rhs1 , basis_name , 0 )
2156- && operand_equal_p (rhs2 , bump_tree , 0 ))
2157- || (operand_equal_p (rhs1 , bump_tree , 0 )
2158- && operand_equal_p (rhs2 , basis_name , 0 ))))
2159- {
2160- if (dump_file && (dump_flags & TDF_DETAILS ))
2161- {
2162- fputs ("(duplicate, not actually replacing)" , dump_file );
2163- stmt_to_print = c -> cand_stmt ;
2164- }
2165- }
2166- else
2167- {
2168- gimple_stmt_iterator gsi = gsi_for_stmt (c -> cand_stmt );
2169- slsr_cand_t cc = c ;
2170- gimple_assign_set_rhs_with_ops (& gsi , code ,
2171- basis_name , bump_tree );
2172- update_stmt (gsi_stmt (gsi ));
2173- c -> cand_stmt = gsi_stmt (gsi );
2174- while (cc -> next_interp )
2175- {
2176- cc = lookup_cand (cc -> next_interp );
2177- cc -> cand_stmt = gsi_stmt (gsi );
2178- }
2179- if (dump_file && (dump_flags & TDF_DETAILS ))
2180- stmt_to_print = gsi_stmt (gsi );
2181- }
2181+ stmt_to_print = gsi_stmt (gsi );
21822182 }
2183+ }
21832184
2184- if (dump_file && (dump_flags & TDF_DETAILS ))
2185- {
2186- fputs ("With: " , dump_file );
2187- print_gimple_stmt (dump_file , stmt_to_print , 0 );
2188- fputs ("\n" , dump_file );
2189- }
2185+ if (dump_file && (dump_flags & TDF_DETAILS ))
2186+ {
2187+ fputs ("With: " , dump_file );
2188+ print_gimple_stmt (dump_file , stmt_to_print , 0 );
2189+ fputs ("\n" , dump_file );
21902190 }
21912191}
21922192
0 commit comments