public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1349] Fix PR 100925: Limit some a?CST1:CST2 optimizations to intergal types only
@ 2021-06-09 19:20 Andrew Pinski
  0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2021-06-09 19:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d4faa36e7540c573c5dc17850bcd938d0900b2e9

commit r12-1349-gd4faa36e7540c573c5dc17850bcd938d0900b2e9
Author: Andrew Pinski <apinski@marvell.com>
Date:   Sat Jun 5 21:25:58 2021 -0700

    Fix PR 100925: Limit some a?CST1:CST2 optimizations to intergal types only
    
    The problem here is with offset (and pointer) types is we produce
    a negative expression when this optimization hits.
    It is easier to disable this optimization for all non-integeral types
    instead of finding an integer type which is the same precission as the
    type to do the negative expression on it.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
    
    gcc/ChangeLog:
    
            PR tree-optimization/100925
            * match.pd (a ? CST1 : CST2): Limit transformations
            that would produce a negative to integeral types only.
            Change !POINTER_TYPE_P to INTEGRAL_TYPE_P also.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/torture/pr100925.C: New test.

Diff:
---
 gcc/match.pd                            |  8 ++++----
 gcc/testsuite/g++.dg/torture/pr100925.C | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index d06ff170684..bf22bc3a198 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3733,10 +3733,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     (if (integer_onep (@1))
      (convert (convert:boolean_type_node @0)))
     /* a ? -1 : 0 -> -a. */
-    (if (integer_all_onesp (@1))
+    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
      (negate (convert (convert:boolean_type_node @0))))
     /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */
-    (if (!POINTER_TYPE_P (type) && integer_pow2p (@1))
+    (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@1))
      (with {
        tree shift = build_int_cst (integer_type_node, tree_log2 (@1));
       }
@@ -3750,10 +3750,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      (if (integer_onep (@2))
       (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
      /* a ? -1 : 0 -> -(!a). */
-     (if (integer_all_onesp (@2))
+     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
       (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))))
      /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
-     (if (!POINTER_TYPE_P (type) && integer_pow2p (@2))
+     (if (INTEGRAL_TYPE_P (type) &&  integer_pow2p (@2))
       (with {
 	tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
        }
diff --git a/gcc/testsuite/g++.dg/torture/pr100925.C b/gcc/testsuite/g++.dg/torture/pr100925.C
new file mode 100644
index 00000000000..de13950dca0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr100925.C
@@ -0,0 +1,24 @@
+// { dg-do compile }
+
+struct QScopedPointerDeleter {
+  static void cleanup(int *);
+};
+class QScopedPointer {
+  typedef int *QScopedPointer::*RestrictedBool;
+
+public:
+  operator RestrictedBool() { return d ? nullptr : &QScopedPointer::d; }
+  void reset() {
+    if (d)
+      QScopedPointerDeleter::cleanup(d);
+  }
+  int *d;
+};
+class DOpenGLPaintDevicePrivate {
+public:
+  QScopedPointer fbo;
+} DOpenGLPaintDeviceresize_d;
+void DOpenGLPaintDeviceresize() {
+  if (DOpenGLPaintDeviceresize_d.fbo)
+    DOpenGLPaintDeviceresize_d.fbo.reset();
+}


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

only message in thread, other threads:[~2021-06-09 19:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 19:20 [gcc r12-1349] Fix PR 100925: Limit some a?CST1:CST2 optimizations to intergal types only Andrew Pinski

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).