public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2]middle-end: fix wide_int_constant_multiple_p when VAL and DIV are 0.  [PR114932]
@ 2024-07-01 20:13 Tamar Christina
  2024-07-01 20:14 ` [PATCH 2/2]middle-end: replace constant_multiple_of with aff_combination_constant_multiple_p [PR114932] Tamar Christina
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Tamar Christina @ 2024-07-01 20:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther, jlaw

[-- Attachment #1: Type: text/plain, Size: 1782 bytes --]

Hi All,

wide_int_constant_multiple_p tries to check if for two tree expressions a and b
that there is a multiplier which makes a == b * c.

This code however seems to think that there's no c where a=0 and b=0 are equal
which is of course wrong.

This fixes it and also fixes the comment.

Bootstrapped Regtested on aarch64-none-linux-gnu,
x86_64-pc-linux-gnu -m32, -m64 and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	PR tree-optimization/114932
	* tree-affine.cc (wide_int_constant_multiple_p): Support 0 and 0 being
	multiples.

---
diff --git a/gcc/tree-affine.cc b/gcc/tree-affine.cc
index d6309c4390362b680f0aa97a41fac3281ade66fd..bfea0fe826a6affa0ace154e3ca38c9ef632fcba 100644
--- a/gcc/tree-affine.cc
+++ b/gcc/tree-affine.cc
@@ -880,11 +880,10 @@ free_affine_expand_cache (hash_map<tree, name_expansion *> **cache)
   *cache = NULL;
 }
 
-/* If VAL != CST * DIV for any constant CST, returns false.
-   Otherwise, if *MULT_SET is true, additionally compares CST and MULT,
-   and if they are different, returns false.  Finally, if neither of these
-   two cases occur, true is returned, and CST is stored to MULT and MULT_SET
-   is set to true.  */
+/* If VAL == CST * DIV for any constant CST, returns true.
+   and if *MULT_SET is true, additionally compares CST and MULT
+   and if they are different, returns false.  If true is returned, CST is
+   stored to MULT and MULT_SET is set to true.  */
 
 static bool
 wide_int_constant_multiple_p (const poly_widest_int &val,
@@ -895,6 +894,12 @@ wide_int_constant_multiple_p (const poly_widest_int &val,
 
   if (known_eq (val, 0))
     {
+      if (maybe_eq (div, 0))
+	{
+	  *mult = 1;
+	  return true;
+	}
+
       if (*mult_set && maybe_ne (*mult, 0))
 	return false;
       *mult_set = true;




-- 

[-- Attachment #2: rb18602.patch --]
[-- Type: text/x-diff, Size: 1225 bytes --]

diff --git a/gcc/tree-affine.cc b/gcc/tree-affine.cc
index d6309c4390362b680f0aa97a41fac3281ade66fd..bfea0fe826a6affa0ace154e3ca38c9ef632fcba 100644
--- a/gcc/tree-affine.cc
+++ b/gcc/tree-affine.cc
@@ -880,11 +880,10 @@ free_affine_expand_cache (hash_map<tree, name_expansion *> **cache)
   *cache = NULL;
 }
 
-/* If VAL != CST * DIV for any constant CST, returns false.
-   Otherwise, if *MULT_SET is true, additionally compares CST and MULT,
-   and if they are different, returns false.  Finally, if neither of these
-   two cases occur, true is returned, and CST is stored to MULT and MULT_SET
-   is set to true.  */
+/* If VAL == CST * DIV for any constant CST, returns true.
+   and if *MULT_SET is true, additionally compares CST and MULT
+   and if they are different, returns false.  If true is returned, CST is
+   stored to MULT and MULT_SET is set to true.  */
 
 static bool
 wide_int_constant_multiple_p (const poly_widest_int &val,
@@ -895,6 +894,12 @@ wide_int_constant_multiple_p (const poly_widest_int &val,
 
   if (known_eq (val, 0))
     {
+      if (maybe_eq (div, 0))
+	{
+	  *mult = 1;
+	  return true;
+	}
+
       if (*mult_set && maybe_ne (*mult, 0))
 	return false;
       *mult_set = true;




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

end of thread, other threads:[~2024-07-02 20:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-01 20:13 [PATCH 1/2]middle-end: fix wide_int_constant_multiple_p when VAL and DIV are 0. [PR114932] Tamar Christina
2024-07-01 20:14 ` [PATCH 2/2]middle-end: replace constant_multiple_of with aff_combination_constant_multiple_p [PR114932] Tamar Christina
2024-07-02  7:58   ` Richard Biener
2024-07-01 20:32 ` [PATCH 1/2]middle-end: fix wide_int_constant_multiple_p when VAL and DIV are 0. [PR114932] Tamar Christina
2024-07-02  8:01   ` Richard Biener
2024-07-02  9:46     ` Alex Coplan
2024-07-02 10:17       ` Alex Coplan
2024-07-02 11:41         ` Richard Biener
2024-07-02 13:36           ` Alex Coplan
2024-07-02 20:00             ` Richard Sandiford
2024-07-02  7:56 ` 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).