tree-optimization/106112 - fix CSE from wider operation
authorRichard Biener <rguenther@suse.de>
Tue, 28 Jun 2022 11:57:29 +0000 (13:57 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 19 Jul 2022 09:26:53 +0000 (11:26 +0200)
The following fixes a mistake in looking up an extended operand
in the CSE of a truncated operation.

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.

(cherry picked from commit 2dbb45d6dc0d20dc159b3d8e27ebb6825074827a)

gcc/testsuite/gcc.dg/torture/pr106112.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr106112.c b/gcc/testsuite/gcc.dg/torture/pr106112.c
new file mode 100644 (file)
index 0000000..bd7f63c
--- /dev/null
@@ -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;
+}
index d9eaaa9..cd57379 100644 (file)
@@ -4909,7 +4909,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;
 }