]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/114672 - WIDEN_MULT_PLUS_EXPR type mismatch
authorRichard Biener <rguenther@suse.de>
Wed, 10 Apr 2024 08:33:40 +0000 (10:33 +0200)
committerRichard Ball <richard.ball@arm.com>
Thu, 2 May 2024 19:21:03 +0000 (20:21 +0100)
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.

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.

(cherry picked from commit 912753cc5f18d786e334dd425469fa7f93155661)

gcc/testsuite/gcc.dg/torture/pr114672.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr114672.c b/gcc/testsuite/gcc.dg/torture/pr114672.c
new file mode 100644 (file)
index 0000000..b69511f
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+struct {
+  __INT64_TYPE__ m : 60;
+} s;
+
+short a;
+short b;
+
+void
+foo ()
+{
+  s.m += a * b;
+}
index ff949e4fec9c33bf99d83f4d62454a9022b4b3b7..08cf33214ad3d87e9f138aad6d82c060428177a9 100644 (file)
@@ -2875,8 +2875,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)