]> gcc.gnu.org Git - gcc.git/commitdiff
match.pd: Further complex simplification fixes [PR104675]
authorJakub Jelinek <jakub@redhat.com>
Fri, 25 Feb 2022 20:25:12 +0000 (21:25 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 10 May 2022 08:14:34 +0000 (10:14 +0200)
Mark mentioned in the PR further 2 simplifications that also ICE
with complex types.
For these, eventually (but IMO GCC 13 materials) we could support it
for vector types if it would be uniform vector constants.
Currently integer_pow2p is true only for INTEGER_CSTs and COMPLEX_CSTs
and we can't use bit_and etc. for complex type.

2022-02-25  Jakub Jelinek  <jakub@redhat.com>
    Marc Glisse  <marc.glisse@inria.fr>

PR tree-optimization/104675
* match.pd (t * 2U / 2 -> t & (~0 / 2), t / 2U * 2 -> t & ~1):
Restrict simplifications to INTEGRAL_TYPE_P.

* gcc.dg/pr104675-3.c : New test.

(cherry picked from commit f62115c9b770a66c5378f78a2d5866243d560573)

gcc/match.pd
gcc/testsuite/gcc.dg/pr104675-3.c [new file with mode: 0644]

index 16d376453f658eec6e787669c3d5d3aab2f40ada..1a4f0dab4639e61b93bc476d145700b621e23567 100644 (file)
@@ -615,7 +615,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
 (simplify
  (trunc_div (mult @0 integer_pow2p@1) @1)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 { wide_int_to_tree
                (type, wi::mask (TYPE_PRECISION (type)
                                 - wi::exact_log2 (wi::to_wide (@1)),
@@ -624,7 +624,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1.  */
 (simplify
  (mult (trunc_div @0 integer_pow2p@1) @1)
- (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 (negate @1))))
 
 /* Simplify (t * 2) / 2) -> t.  */
diff --git a/gcc/testsuite/gcc.dg/pr104675-3.c b/gcc/testsuite/gcc.dg/pr104675-3.c
new file mode 100644 (file)
index 0000000..3b2eb64
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR tree-optimization/104675 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+_Complex unsigned int
+foo (_Complex unsigned int x)
+{
+  return (x / 2) * 2;
+}
+
+_Complex unsigned int
+bar (_Complex unsigned int x)
+{
+  return (x * 2) / 2;
+}
+
+_Complex unsigned int
+baz (_Complex unsigned int x)
+{
+  _Complex unsigned int y = x / 2;
+  return y * 2;
+}
+
+_Complex unsigned int
+qux (_Complex unsigned int x)
+{
+  _Complex unsigned int y = x * 2;
+  return y / 2;
+}
This page took 0.077083 seconds and 5 git commands to generate.