public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/114672 - WIDEN_MULT_PLUS_EXPR type mismatch
@ 2024-04-10 16:31 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2024-04-10 16:31 UTC (permalink / raw)
  To: gcc-patches

The following makes sure to restrict WIDEN_MULT*_EXPR to a mode
precision final compute type as the mode is used to find the optab
and type checking chokes when seeing bit-precisions later which
would likely also not properly expanded to RTL.

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

	PR tree-optimization/114672
	* tree-ssa-math-opts.cc (convert_plusminus_to_widen): Only
	allow mode-precision results.

	* gcc.dg/torture/pr114672.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr114672.c | 14 ++++++++++++++
 gcc/tree-ssa-math-opts.cc               |  5 +++--
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr114672.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr114672.c b/gcc/testsuite/gcc.dg/torture/pr114672.c
new file mode 100644
index 00000000000..b69511fe8db
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr114672.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+struct {
+  __INT64_TYPE__ m : 60;
+} s;
+
+short a;
+short b;
+
+void
+foo ()
+{
+  s.m += a * b;
+}
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index a8d25c2de48..705f4a4695a 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -2918,8 +2918,9 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple *stmt,
 
   lhs = gimple_assign_lhs (stmt);
   type = TREE_TYPE (lhs);
-  if (TREE_CODE (type) != INTEGER_TYPE
-      && TREE_CODE (type) != FIXED_POINT_TYPE)
+  if ((TREE_CODE (type) != INTEGER_TYPE
+       && TREE_CODE (type) != FIXED_POINT_TYPE)
+      || !type_has_mode_precision_p (type))
     return false;
 
   if (code == MINUS_EXPR)
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-10 16:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-10 16:31 [PATCH] tree-optimization/114672 - WIDEN_MULT_PLUS_EXPR type mismatch 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).