aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorVladimir N. Makarov <vmakarov@redhat.com>2021-12-02 12:31:28 -0500
committerVladimir N. Makarov <vmakarov@redhat.com>2021-12-02 12:39:05 -0500
commitcd47cd4b5eb2dfa7a3190e46a3ae93cc87dbe6b1 (patch)
treeb0d60bfcf433804c0b7fea269a5c71e3fa3334c4 /gcc
parentacf4fe96f12341da253fa9a932947581690122a4 (diff)
downloadgcc-cd47cd4b5eb2dfa7a3190e46a3ae93cc87dbe6b1.zip
gcc-cd47cd4b5eb2dfa7a3190e46a3ae93cc87dbe6b1.tar.gz
gcc-cd47cd4b5eb2dfa7a3190e46a3ae93cc87dbe6b1.tar.bz2
[PR103437] Make backup code for overflow conditional
Switch off long long variant overflow code by preprocessor if the build compiler has __builtin_smul_overflow. gcc/ChangeLog: PR rtl-optimization/103437 * ira-color.c (setup_allocno_priorities): Switch off backup code for overflow if compiler has __builtin_smul_overflow. Use < for comparison with -INT_MAX.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ira-color.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/gcc/ira-color.c b/gcc/ira-color.c
index 3b19a58..a1b0277 100644
--- a/gcc/ira-color.c
+++ b/gcc/ira-color.c
@@ -2797,7 +2797,6 @@ static void
setup_allocno_priorities (ira_allocno_t *consideration_allocnos, int n)
{
int i, length, nrefs, priority, max_priority, mult, diff;
- bool overflow_backup_p = true;
ira_allocno_t a;
max_priority = 0;
@@ -2810,27 +2809,27 @@ setup_allocno_priorities (ira_allocno_t *consideration_allocnos, int n)
ira_assert (mult >= 0);
mult *= ira_reg_class_max_nregs[ALLOCNO_CLASS (a)][ALLOCNO_MODE (a)];
diff = ALLOCNO_MEMORY_COST (a) - ALLOCNO_CLASS_COST (a);
- /* Multiplication can overflow for very large functions.
- Check the overflow and constrain the result if necessary: */
#ifdef __has_builtin
#if __has_builtin(__builtin_smul_overflow)
- overflow_backup_p = false;
+#define HAS_SMUL_OVERFLOW
+#endif
+#endif
+ /* Multiplication can overflow for very large functions.
+ Check the overflow and constrain the result if necessary: */
+#ifdef HAS_SMUL_OVERFLOW
if (__builtin_smul_overflow (mult, diff, &priority)
- || priority <= -INT_MAX)
+ || priority < -INT_MAX)
priority = diff >= 0 ? INT_MAX : -INT_MAX;
+#else
+ static_assert
+ (sizeof (long long) >= 2 * sizeof (int),
+ "overflow code does not work for such int and long long sizes");
+ long long priorityll = (long long) mult * diff;
+ if (priorityll < -INT_MAX || priorityll > INT_MAX)
+ priority = diff >= 0 ? INT_MAX : -INT_MAX;
+ else
+ priority = priorityll;
#endif
-#endif
- if (overflow_backup_p)
- {
- static_assert
- (sizeof (long long) >= 2 * sizeof (int),
- "overflow code does not work for such int and long long sizes");
- long long priorityll = (long long) mult * diff;
- if (priorityll < -INT_MAX || priorityll > INT_MAX)
- priority = diff >= 0 ? INT_MAX : -INT_MAX;
- else
- priority = priorityll;
- }
allocno_priorities[ALLOCNO_NUM (a)] = priority;
if (priority < 0)
priority = -priority;