diff mbox series

Avoid division by zero in fold_loop_internal_call

Message ID ZNpPecZj12tk5zbn@kam.mff.cuni.cz
State New
Headers show
Series Avoid division by zero in fold_loop_internal_call | expand

Commit Message

Jan Hubicka Aug. 14, 2023, 3:59 p.m. UTC
Hi,
My patch to fix profile after folding internal call is missing check for the
case profile was already zero before if-conversion.

Bootstrapped/regtested x86_64-linux, comitted.

gcc/ChangeLog:

	PR gcov-profile/110988
	* tree-cfg.cc (fold_loop_internal_call): Avoid division by zero.
diff mbox series

Patch

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index ab1f8067c54..105f4b1c953 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -7734,11 +7734,14 @@  fold_loop_internal_call (gimple *g, tree value)
 		 test.  This should not happen as the guarded code should
 		 start with pre-header.  */
 	      gcc_assert (single_pred_edge (taken_edge->dest));
-	      taken_edge->dest->count
-		= taken_edge->dest->count.apply_scale (new_count,
-						       old_count);
-	      scale_strictly_dominated_blocks (taken_edge->dest,
-					       new_count, old_count);
+	      if (old_count.nonzero_p ())
+		{
+		  taken_edge->dest->count
+		    = taken_edge->dest->count.apply_scale (new_count,
+							   old_count);
+		  scale_strictly_dominated_blocks (taken_edge->dest,
+						   new_count, old_count);
+		}
 	    }
 	}
     }