public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Reduce multiple_of_p uses
@ 2022-01-24 14:45 Richard Biener
  2022-01-28 18:03 ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2022-01-24 14:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford

There are a few cases where we know we're dealing with (poly-)integer
constants, so remove the use of multiple_of_p in those cases to make
the PR100499 fix less impactful.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

OK?

Thanks,
Richard.

2022-01-24  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/100499
	* tree-cfg.cc (verify_gimple_assign_ternary): Use multiple_p
	on poly-ints instead of multiple_of_p.
	* tree-ssa.cc (maybe_rewrite_mem_ref_base): Likewise.
	(non_rewritable_mem_ref_base): Likewise.
	(non_rewritable_lvalue_p): Likewise.
	(execute_update_addresses_taken): Likewise.
---
 gcc/tree-cfg.cc |  3 ++-
 gcc/tree-ssa.cc | 18 +++++++++---------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index 77178a6bf69..2340cd7cef0 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -4410,7 +4410,8 @@ verify_gimple_assign_ternary (gassign *stmt)
 					TREE_TYPE (rhs2_type))
 		 && multiple_p (TYPE_VECTOR_SUBPARTS (rhs1_type),
 				TYPE_VECTOR_SUBPARTS (rhs2_type))
-		 && multiple_of_p (bitsizetype, rhs3, TYPE_SIZE (rhs2_type)))))
+		 && multiple_p (wi::to_poly_offset (rhs3),
+				wi::to_poly_offset (TYPE_SIZE (rhs2_type))))))
 	{
 	  error ("not allowed type combination in %qs", code_name);
 	  debug_generic_expr (rhs1_type);
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index 613ab05d557..8fe0682981d 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1417,8 +1417,8 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
       if (TREE_CODE (TREE_TYPE (sym)) == VECTOR_TYPE
 	  && useless_type_conversion_p (TREE_TYPE (*tp),
 					TREE_TYPE (TREE_TYPE (sym)))
-	  && multiple_of_p (sizetype, TREE_OPERAND (*tp, 1),
-			    TYPE_SIZE_UNIT (TREE_TYPE (*tp))))
+	  && multiple_p (mem_ref_offset (*tp),
+			 wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
 	{
 	  *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym, 
 			TYPE_SIZE (TREE_TYPE (*tp)),
@@ -1504,8 +1504,8 @@ non_rewritable_mem_ref_base (tree ref)
 	  && known_ge (mem_ref_offset (base), 0)
 	  && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
 		       mem_ref_offset (base))
-	  && multiple_of_p (sizetype, TREE_OPERAND (base, 1),
-			    TYPE_SIZE_UNIT (TREE_TYPE (base))))
+	  && multiple_p (mem_ref_offset (base),
+			 wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (base)))))
 	return NULL_TREE;
       /* For same sizes and zero offset we can use a VIEW_CONVERT_EXPR.  */
       if (integer_zerop (TREE_OPERAND (base, 1))
@@ -1596,8 +1596,8 @@ non_rewritable_lvalue_p (tree lhs)
 	  && known_ge (mem_ref_offset (lhs), 0)
 	  && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
 		       mem_ref_offset (lhs))
-	  && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1),
-			    TYPE_SIZE_UNIT (TREE_TYPE (lhs)))
+	  && multiple_p (mem_ref_offset (lhs),
+			 wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
 	  && known_ge (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (decl))),
 		       wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (lhs)))))
 	{
@@ -1969,9 +1969,9 @@ execute_update_addresses_taken (void)
 		    && known_gt (wi::to_poly_offset
 				   (TYPE_SIZE_UNIT (TREE_TYPE (sym))),
 				 mem_ref_offset (lhs))
-		    && multiple_of_p (sizetype,
-				      TREE_OPERAND (lhs, 1),
-				      TYPE_SIZE_UNIT (TREE_TYPE (lhs))))
+		    && multiple_p (mem_ref_offset (lhs),
+				   wi::to_poly_offset
+				     (TYPE_SIZE_UNIT (TREE_TYPE (lhs)))))
 		  {
 		    tree val = gimple_assign_rhs1 (stmt);
 		    if (! types_compatible_p (TREE_TYPE (val),
-- 
2.31.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Reduce multiple_of_p uses
  2022-01-24 14:45 [PATCH] Reduce multiple_of_p uses Richard Biener
@ 2022-01-28 18:03 ` Jeff Law
  2022-01-31  8:08   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2022-01-28 18:03 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: richard.sandiford



On 1/24/2022 7:45 AM, Richard Biener via Gcc-patches wrote:
> There are a few cases where we know we're dealing with (poly-)integer
> constants, so remove the use of multiple_of_p in those cases to make
> the PR100499 fix less impactful.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?
>
> Thanks,
> Richard.
>
> 2022-01-24  Richard Biener  <rguenther@suse.de>
>
> 	PR tree-optimization/100499
> 	* tree-cfg.cc (verify_gimple_assign_ternary): Use multiple_p
> 	on poly-ints instead of multiple_of_p.
> 	* tree-ssa.cc (maybe_rewrite_mem_ref_base): Likewise.
> 	(non_rewritable_mem_ref_base): Likewise.
> 	(non_rewritable_lvalue_p): Likewise.
> 	(execute_update_addresses_taken): Likewise.
So it's not a full fix for this class of problems, but removes some of 
the cases where we could potentially overflow and give the wrong 
result.  I'd be happier if we had a concrete testcase for these 
instances you're fixing, but I think it's a move in the right direction 
and I obviously trust your judgment on whether or not to install it now 
or wait for gcc-13.

So your call.  Both on whether or not to try and construct testcases to 
trigger these instances and whether or not to install now or wait for 
gcc-13.

jeff


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Reduce multiple_of_p uses
  2022-01-28 18:03 ` Jeff Law
@ 2022-01-31  8:08   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-01-31  8:08 UTC (permalink / raw)
  To: Jeff Law; +Cc: gcc-patches, richard.sandiford

On Fri, 28 Jan 2022, Jeff Law wrote:

> 
> 
> On 1/24/2022 7:45 AM, Richard Biener via Gcc-patches wrote:
> > There are a few cases where we know we're dealing with (poly-)integer
> > constants, so remove the use of multiple_of_p in those cases to make
> > the PR100499 fix less impactful.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> >
> > OK?
> >
> > Thanks,
> > Richard.
> >
> > 2022-01-24  Richard Biener  <rguenther@suse.de>
> >
> >  PR tree-optimization/100499
> >  * tree-cfg.cc (verify_gimple_assign_ternary): Use multiple_p
> >  on poly-ints instead of multiple_of_p.
> >  * tree-ssa.cc (maybe_rewrite_mem_ref_base): Likewise.
> >  (non_rewritable_mem_ref_base): Likewise.
> >  (non_rewritable_lvalue_p): Likewise.
> >  (execute_update_addresses_taken): Likewise.
> So it's not a full fix for this class of problems, but removes some of the
> cases where we could potentially overflow and give the wrong result.  I'd be
> happier if we had a concrete testcase for these instances you're fixing, but I
> think it's a move in the right direction and I obviously trust your judgment
> on whether or not to install it now or wait for gcc-13.

No, multiple_of_p has no issues with these cases since we only ever pass
it [POLY_]INT_CSTs, it's just that there's no need to use multiple_of_p
since we have a better tool for these cases (and thus later do not have
to decide whether to use the no-wrap or wrap variant).

> So your call.  Both on whether or not to try and construct testcases to
> trigger these instances and whether or not to install now or wait for gcc-13.

I've pushed it now.

Richard.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-31  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 14:45 [PATCH] Reduce multiple_of_p uses Richard Biener
2022-01-28 18:03 ` Jeff Law
2022-01-31  8:08   ` 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).