https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81503
--- Comment #8 from Bill Schmidt <wschmidt at gcc dot gnu.org> ---
Patch under test that fixes this case:
Index: gcc/gimple-ssa-strength-reduction.c
===================================================================
--- gcc/gimple-ssa-strength-reduction.c (revision 250791)
+++ gcc/gimple-ssa-strength-reduction.c (working copy)
@@ -2082,6 +2082,11 @@ replace_mult_candidate (slsr_cand_t c, tree basis_
types but allows for safe negation without twisted logic. */
if (wi::fits_shwi_p (bump)
&& bump.to_shwi () != HOST_WIDE_INT_MIN
+ /* It is more likely that the bump doesn't fit in the target
+ type, so check whether constraining it to that type changes
+ the value. */
+ && wi::eq_p (TREE_INT_CST_LOW (wide_int_to_tree (target_type, bump)),
+ bump)
/* It is not useful to replace casts, copies, negates, or adds of
an SSA name and a constant. */
&& cand_code != SSA_NAME