@@ -9599,7 +9599,12 @@ simplify_cond_using_ranges (gcond *stmt)
with strict overflow semantics. */
&& ((!is_negative_overflow_infinity (vr->min)
&& !is_positive_overflow_infinity (vr->max))
- || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (innerop))))
+ || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (innerop)))
+ /* If the only use of INNEROP is the cast to OP0, and OP0 is also
+ used in other places, folding would introduce new uses of the
+ otherwise dead INNEROP without eliminating OP0, so do not
+ fold. */
+ && (!has_single_use (innerop) || has_single_use (op0)))
{
/* If the range overflowed and the user has asked for warnings
when strict overflow semantics were used to optimize code,