aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Schulze Frielinghaus <stefansf@linux.ibm.com>2023-08-02 21:43:22 +0200
committerStefan Schulze Frielinghaus <stefansf@linux.ibm.com>2023-08-02 21:43:22 +0200
commit41ef5a34161356817807be3a2e51fbdbe575ae85 (patch)
tree33f177f85020d0c2baf7610892e3cc1ab698f1b4
parent1d5bc3285e8a115538442dc2aaa34d2b509e1f6e (diff)
downloadgcc-41ef5a34161356817807be3a2e51fbdbe575ae85.zip
gcc-41ef5a34161356817807be3a2e51fbdbe575ae85.tar.gz
gcc-41ef5a34161356817807be3a2e51fbdbe575ae85.tar.bz2
rtl-optimization/110867 Fix narrow comparison of memory and constant
In certain cases a constant may not fit into the mode used to perform a comparison. This may be the case for sign-extended constants which are used during an unsigned comparison as e.g. in (set (reg:CC 100 cc) (compare:CC (mem:SI (reg/v/f:SI 115 [ a ]) [1 *a_4(D)+0 S4 A64]) (const_int -2147483648 [0xffffffff80000000]))) Fixed by ensuring that the constant fits into comparison mode. Furthermore, on some targets as e.g. sparc the constant used in a comparison is chopped off before combine which leads to failing test cases (see PR 110869). Fixed by not requiring that the source mode has to be DImode, and excluding sparc from the last two test cases entirely since there the constant cannot be further reduced. gcc/ChangeLog: PR rtl-optimization/110867 * combine.cc (simplify_compare_const): Try the optimization only in case the constant fits into the comparison mode. gcc/testsuite/ChangeLog: PR rtl-optimization/110869 * gcc.dg/cmp-mem-const-1.c: Relax mode for constant. * gcc.dg/cmp-mem-const-2.c: Relax mode for constant. * gcc.dg/cmp-mem-const-3.c: Relax mode for constant. * gcc.dg/cmp-mem-const-4.c: Relax mode for constant. * gcc.dg/cmp-mem-const-5.c: Exclude sparc since here the constant is already reduced. * gcc.dg/cmp-mem-const-6.c: Exclude sparc since here the constant is already reduced.
-rw-r--r--gcc/combine.cc4
-rw-r--r--gcc/testsuite/gcc.dg/cmp-mem-const-1.c2
-rw-r--r--gcc/testsuite/gcc.dg/cmp-mem-const-2.c2
-rw-r--r--gcc/testsuite/gcc.dg/cmp-mem-const-3.c2
-rw-r--r--gcc/testsuite/gcc.dg/cmp-mem-const-4.c2
-rw-r--r--gcc/testsuite/gcc.dg/cmp-mem-const-5.c4
-rw-r--r--gcc/testsuite/gcc.dg/cmp-mem-const-6.c4
7 files changed, 12 insertions, 8 deletions
diff --git a/gcc/combine.cc b/gcc/combine.cc
index 0d99fa5..e46d202 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -11998,11 +11998,15 @@ simplify_compare_const (enum rtx_code code, machine_mode mode,
x0 >= 0x40. */
if ((code == LEU || code == LTU || code == GEU || code == GTU)
&& is_a <scalar_int_mode> (GET_MODE (op0), &int_mode)
+ && HWI_COMPUTABLE_MODE_P (int_mode)
&& MEM_P (op0)
&& !MEM_VOLATILE_P (op0)
/* The optimization makes only sense for constants which are big enough
so that we have a chance to chop off something at all. */
&& (unsigned HOST_WIDE_INT) const_op > 0xff
+ /* Bail out, if the constant does not fit into INT_MODE. */
+ && (unsigned HOST_WIDE_INT) const_op
+ < ((HOST_WIDE_INT_1U << (GET_MODE_PRECISION (int_mode) - 1) << 1) - 1)
/* Ensure that we do not overflow during normalization. */
&& (code != GTU || (unsigned HOST_WIDE_INT) const_op < HOST_WIDE_INT_M1U))
{
diff --git a/gcc/testsuite/gcc.dg/cmp-mem-const-1.c b/gcc/testsuite/gcc.dg/cmp-mem-const-1.c
index 263ad98..4f21a1a 100644
--- a/gcc/testsuite/gcc.dg/cmp-mem-const-1.c
+++ b/gcc/testsuite/gcc.dg/cmp-mem-const-1.c
@@ -1,6 +1,6 @@
/* { dg-do compile { target { lp64 } } } */
/* { dg-options "-O1 -fdump-rtl-combine-details" } */
-/* { dg-final { scan-rtl-dump "narrow comparison from mode DI to QI" "combine" } } */
+/* { dg-final { scan-rtl-dump "narrow comparison from mode .I to QI" "combine" } } */
typedef __UINT64_TYPE__ uint64_t;
diff --git a/gcc/testsuite/gcc.dg/cmp-mem-const-2.c b/gcc/testsuite/gcc.dg/cmp-mem-const-2.c
index a7cc534..7b72295 100644
--- a/gcc/testsuite/gcc.dg/cmp-mem-const-2.c
+++ b/gcc/testsuite/gcc.dg/cmp-mem-const-2.c
@@ -1,6 +1,6 @@
/* { dg-do compile { target { lp64 } } } */
/* { dg-options "-O1 -fdump-rtl-combine-details" } */
-/* { dg-final { scan-rtl-dump "narrow comparison from mode DI to QI" "combine" } } */
+/* { dg-final { scan-rtl-dump "narrow comparison from mode .I to QI" "combine" } } */
typedef __UINT64_TYPE__ uint64_t;
diff --git a/gcc/testsuite/gcc.dg/cmp-mem-const-3.c b/gcc/testsuite/gcc.dg/cmp-mem-const-3.c
index 06f80bf..ed5059d 100644
--- a/gcc/testsuite/gcc.dg/cmp-mem-const-3.c
+++ b/gcc/testsuite/gcc.dg/cmp-mem-const-3.c
@@ -1,6 +1,6 @@
/* { dg-do compile { target { lp64 } } } */
/* { dg-options "-O1 -fdump-rtl-combine-details" } */
-/* { dg-final { scan-rtl-dump "narrow comparison from mode DI to HI" "combine" } } */
+/* { dg-final { scan-rtl-dump "narrow comparison from mode .I to HI" "combine" } } */
typedef __UINT64_TYPE__ uint64_t;
diff --git a/gcc/testsuite/gcc.dg/cmp-mem-const-4.c b/gcc/testsuite/gcc.dg/cmp-mem-const-4.c
index 407999a..23e8337 100644
--- a/gcc/testsuite/gcc.dg/cmp-mem-const-4.c
+++ b/gcc/testsuite/gcc.dg/cmp-mem-const-4.c
@@ -1,6 +1,6 @@
/* { dg-do compile { target { lp64 } } } */
/* { dg-options "-O1 -fdump-rtl-combine-details" } */
-/* { dg-final { scan-rtl-dump "narrow comparison from mode DI to HI" "combine" } } */
+/* { dg-final { scan-rtl-dump "narrow comparison from mode .I to HI" "combine" } } */
typedef __UINT64_TYPE__ uint64_t;
diff --git a/gcc/testsuite/gcc.dg/cmp-mem-const-5.c b/gcc/testsuite/gcc.dg/cmp-mem-const-5.c
index e16773f..d266896 100644
--- a/gcc/testsuite/gcc.dg/cmp-mem-const-5.c
+++ b/gcc/testsuite/gcc.dg/cmp-mem-const-5.c
@@ -1,6 +1,6 @@
-/* { dg-do compile { target { lp64 } } } */
+/* { dg-do compile { target { lp64 } && ! target { sparc*-*-* } } } */
/* { dg-options "-O1 -fdump-rtl-combine-details" } */
-/* { dg-final { scan-rtl-dump "narrow comparison from mode DI to SI" "combine" } } */
+/* { dg-final { scan-rtl-dump "narrow comparison from mode .I to SI" "combine" } } */
typedef __UINT64_TYPE__ uint64_t;
diff --git a/gcc/testsuite/gcc.dg/cmp-mem-const-6.c b/gcc/testsuite/gcc.dg/cmp-mem-const-6.c
index 8f53b56..68d7a9d 100644
--- a/gcc/testsuite/gcc.dg/cmp-mem-const-6.c
+++ b/gcc/testsuite/gcc.dg/cmp-mem-const-6.c
@@ -1,6 +1,6 @@
-/* { dg-do compile { target { lp64 } } } */
+/* { dg-do compile { target { lp64 } && ! target { sparc*-*-* } } } */
/* { dg-options "-O1 -fdump-rtl-combine-details" } */
-/* { dg-final { scan-rtl-dump "narrow comparison from mode DI to SI" "combine" } } */
+/* { dg-final { scan-rtl-dump "narrow comparison from mode .I to SI" "combine" } } */
typedef __UINT64_TYPE__ uint64_t;