public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/106112 - fix CSE from wider operation
@ 2022-06-29  9:13 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-29  9:13 UTC (permalink / raw)
  To: gcc-patches

The following fixes a mistake in looking up an extended operand
in the CSE of a truncated operation.

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

2022-06-28  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/106112
	* tree-ssa-sccvn.cc (valueized_wider_op): Properly extend
	a constant operand according to its type.

	* gcc.dg/torture/pr106112.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106112.c | 16 ++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106112.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106112.c b/gcc/testsuite/gcc.dg/torture/pr106112.c
new file mode 100644
index 00000000000..bd7f63c0935
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106112.c
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+__INT32_TYPE__ a = 5, b, c, d;
+__UINT64_TYPE__ e = 20862985922;
+int main()
+{
+  __UINT32_TYPE__ f = 4294967292;
+  e = e | f;
+  c = -1 % ((~f ^ 4294967292) - (e - d));
+  b = ~-~e % ~-d;
+  if (b)
+    a = 0;
+  if (a < 1)
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 5214f142f52..9deedeac378 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -4983,7 +4983,7 @@ valueized_wider_op (tree wide_type, tree op, bool allow_truncate)
 
   /* For constants simply extend it.  */
   if (TREE_CODE (op) == INTEGER_CST)
-    return wide_int_to_tree (wide_type, wi::to_wide (op));
+    return wide_int_to_tree (wide_type, wi::to_widest (op));
 
   return NULL_TREE;
 }
-- 
2.35.3

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

* [PATCH] tree-optimization/106112 - fix CSE from wider operation
@ 2022-06-29  9:13 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-29  9:13 UTC (permalink / raw)
  To: gcc-patches

The following fixes a mistake in looking up an extended operand
in the CSE of a truncated operation.

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

2022-06-28  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/106112
	* tree-ssa-sccvn.cc (valueized_wider_op): Properly extend
	a constant operand according to its type.

	* gcc.dg/torture/pr106112.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106112.c | 16 ++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106112.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106112.c b/gcc/testsuite/gcc.dg/torture/pr106112.c
new file mode 100644
index 00000000000..bd7f63c0935
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106112.c
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+__INT32_TYPE__ a = 5, b, c, d;
+__UINT64_TYPE__ e = 20862985922;
+int main()
+{
+  __UINT32_TYPE__ f = 4294967292;
+  e = e | f;
+  c = -1 % ((~f ^ 4294967292) - (e - d));
+  b = ~-~e % ~-d;
+  if (b)
+    a = 0;
+  if (a < 1)
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 5214f142f52..9deedeac378 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -4983,7 +4983,7 @@ valueized_wider_op (tree wide_type, tree op, bool allow_truncate)
 
   /* For constants simply extend it.  */
   if (TREE_CODE (op) == INTEGER_CST)
-    return wide_int_to_tree (wide_type, wi::to_wide (op));
+    return wide_int_to_tree (wide_type, wi::to_widest (op));
 
   return NULL_TREE;
 }
-- 
2.35.3

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

* [PATCH] tree-optimization/106112 - fix CSE from wider operation
@ 2022-06-29  9:13 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-29  9:13 UTC (permalink / raw)
  To: gcc-patches

The following fixes a mistake in looking up an extended operand
in the CSE of a truncated operation.

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

2022-06-28  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/106112
	* tree-ssa-sccvn.cc (valueized_wider_op): Properly extend
	a constant operand according to its type.

	* gcc.dg/torture/pr106112.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106112.c | 16 ++++++++++++++++
 gcc/tree-ssa-sccvn.cc                   |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106112.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106112.c b/gcc/testsuite/gcc.dg/torture/pr106112.c
new file mode 100644
index 00000000000..bd7f63c0935
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106112.c
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+__INT32_TYPE__ a = 5, b, c, d;
+__UINT64_TYPE__ e = 20862985922;
+int main()
+{
+  __UINT32_TYPE__ f = 4294967292;
+  e = e | f;
+  c = -1 % ((~f ^ 4294967292) - (e - d));
+  b = ~-~e % ~-d;
+  if (b)
+    a = 0;
+  if (a < 1)
+    __builtin_abort();
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 5214f142f52..9deedeac378 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -4983,7 +4983,7 @@ valueized_wider_op (tree wide_type, tree op, bool allow_truncate)
 
   /* For constants simply extend it.  */
   if (TREE_CODE (op) == INTEGER_CST)
-    return wide_int_to_tree (wide_type, wi::to_wide (op));
+    return wide_int_to_tree (wide_type, wi::to_widest (op));
 
   return NULL_TREE;
 }
-- 
2.35.3

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

end of thread, other threads:[~2022-06-29  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29  9:13 [PATCH] tree-optimization/106112 - fix CSE from wider operation Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2022-06-29  9:13 Richard Biener
2022-06-29  9:13 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).