https://gcc.gnu.org/g:7b3966da181fe0c8ad4354b462aee74e6c50ba62

commit r17-6682-g7b3966da181fe0c8ad4354b462aee74e6c50ba62
Author: Richard Biener <[email protected]>
Date:   Wed Nov 25 10:23:44 2026 +0100

    tree-optimization/129012 - avoid UB negating ratio in IVOPTS cost compute
    
    This performs the negation in unsigned.
    
            PR tree-optimization/129012
            * tree-ssa-loop-ivopts.cc (get_computation_cost): Negate
            ratio in unsigned HOST_WIDE_INT.

Diff:
---
 gcc/tree-ssa-loop-ivopts.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index 260f8e9486b7..ac9c506427f7 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -4956,7 +4956,7 @@ get_computation_cost (struct ivopts_data *data, struct 
iv_use *use,
 
   /* Turn a + i * (-c) into a - i * c.  */
   if (ratio < 0 && comp_inv && !integer_zerop (comp_inv))
-    aratio = -ratio;
+    aratio = -(unsigned HOST_WIDE_INT) ratio;
   else
     aratio = ratio;

Reply via email to