diff mbox series

tree-optimization/103759: Truncate unknown to sizetype on compare

Message ID 20211217212347.72617-1-siddhesh@gotplt.org
State New
Headers show
Series tree-optimization/103759: Truncate unknown to sizetype on compare | expand

Commit Message

Siddhesh Poyarekar Dec. 17, 2021, 9:23 p.m. UTC
Since all computations in tree-object-size are now done in sizetype and
not HOST_WIDE_INT, comparisons after conversion to HOST_WIDE_INT would
be incorrect.  Instead, truncate unknown (object_size_type) to sizetype
to compare with the computed size to evaluate if it is unknown.

gcc/ChangeLog:

	PR tree-optimization/103759
	* tree-object-size (size_unknown_p): Construct a size_unknown
	and compare with VAL.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
This fixes all the 32-bit torture failures on i686, tested with
configuration:

--enable-clocale=gnu --with-system-zlib --enable-shared --enable-cet
--with-demangler-in-ld --enable-libmpx i686-linux --with-fpmath=sse
--enable-languages=c,c++,lto --disable-bootstrap

and also with x86_64 to ensure I didn't regress there.  I have a full
bootstrap build and test run in progress.

 gcc/tree-object-size.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

Comments

Jakub Jelinek Dec. 17, 2021, 9:47 p.m. UTC | #1
On Sat, Dec 18, 2021 at 02:53:47AM +0530, Siddhesh Poyarekar wrote:
> Since all computations in tree-object-size are now done in sizetype and
> not HOST_WIDE_INT, comparisons after conversion to HOST_WIDE_INT would
> be incorrect.  Instead, truncate unknown (object_size_type) to sizetype
> to compare with the computed size to evaluate if it is unknown.
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/103759
> 	* tree-object-size (size_unknown_p): Construct a size_unknown
> 	and compare with VAL.

I think you should instead drop initval and unknown inlines and
rewrite size_unknown, size_initval and size_unknown_p to work
directly on trees.
size_initval to
  return ((object_size_type & OST_MINIMUM)
	  ? TYPE_MAX_VALUE (sizetype) : size_zero_node);
size_unknown to
  return ((object_size_type & OST_MINIMUM)
	  ? size_zero_node : TYPE_MAX_VALUE (sizetype));
and size_unknown_p to:
  return ((object_size_type & OST_MINIMUM)
	  ? integer_zerop (val) : integer_all_onesp (val));

	Jakub
diff mbox series

Patch

diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 71f6b747d05..71c7935cb07 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -100,15 +100,6 @@  unknown (int object_size_type)
   return ~initval (object_size_type);
 }
 
-/* Return true if VAL is represents an unknown size for OBJECT_SIZE_TYPE.  */
-
-static inline bool
-size_unknown_p (tree val, int object_size_type)
-{
-  return (tree_fits_uhwi_p (val)
-	  && tree_to_uhwi (val) == unknown (object_size_type));
-}
-
 /* Return a tree with initial value for OBJECT_SIZE_TYPE.  */
 
 static inline tree
@@ -125,6 +116,15 @@  size_unknown (int object_size_type)
   return size_int (unknown (object_size_type));
 }
 
+/* Return true if VAL is represents an unknown size for OBJECT_SIZE_TYPE.  */
+
+static inline bool
+size_unknown_p (tree val, int object_size_type)
+{
+  return (TREE_CODE (val) == INTEGER_CST
+	  && tree_int_cst_compare (val, size_unknown (object_size_type)));
+}
+
 /* Grow object_sizes[OBJECT_SIZE_TYPE] to num_ssa_names.  */
 
 static inline void