public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5813] tree-optimization/112344 - relax final value-replacement fix
@ 2023-11-24  7:50 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-11-24  7:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a7d82b45edeed99a850595eee0e59d16c4df7aff

commit r14-5813-ga7d82b45edeed99a850595eee0e59d16c4df7aff
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Nov 23 09:49:59 2023 +0100

    tree-optimization/112344 - relax final value-replacement fix
    
    The following tries to reduce the number of cases we use an unsigned
    type for the addition when we know the original signed increment was
    OK which is when the total unsigned increment computed fits the signed
    type as well.
    
    This fixes the observed testsuite fallout.
    
            PR tree-optimization/112344
            * tree-chrec.cc (chrec_apply): Only use an unsigned add
            when the overall increment doesn't fit the signed type.

Diff:
---
 gcc/tree-chrec.cc | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-chrec.cc b/gcc/tree-chrec.cc
index f4ba130ba20..e2864e8d131 100644
--- a/gcc/tree-chrec.cc
+++ b/gcc/tree-chrec.cc
@@ -646,9 +646,21 @@ chrec_apply (unsigned var,
 	      res = chrec_fold_multiply (utype,
 					 chrec_convert (utype, chrecr, NULL),
 					 res);
-	      res = chrec_fold_plus (utype,
-				     chrec_convert (utype, chrecl, NULL), res);
-	      res = chrec_convert (type, res, NULL);
+	      /* When the resulting increment fits the original type
+		 do the increment in it.  */
+	      if (TREE_CODE (res) == INTEGER_CST
+		  && int_fits_type_p (res, TREE_TYPE (chrecr)))
+		{
+		  res = chrec_convert (TREE_TYPE (chrecr), res, NULL);
+		  res = chrec_fold_plus (type, chrecl, res);
+		}
+	      else
+		{
+		  res = chrec_fold_plus (utype,
+					 chrec_convert (utype, chrecl, NULL),
+					 res);
+		  res = chrec_convert (type, res, NULL);
+		}
 	    }
 	}
       else if (TREE_CODE (x) == INTEGER_CST

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-24  7:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24  7:50 [gcc r14-5813] tree-optimization/112344 - relax final value-replacement fix Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).