]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR 100925: Limit some a?CST1:CST2 optimizations to intergal types only
authorAndrew Pinski <apinski@marvell.com>
Sun, 6 Jun 2021 04:25:58 +0000 (21:25 -0700)
committerAndrew Pinski <apinski@marvell.com>
Wed, 9 Jun 2021 19:19:43 +0000 (12:19 -0700)
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.

gcc/match.pd
gcc/testsuite/g++.dg/torture/pr100925.C [new file with mode: 0644]

index d06ff170684abb65e30196899774fb85b53ae295..bf22bc3a198afdae741628b2b91807758e1dd386 100644 (file)
@@ -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 (file)
index 0000000..de13950
--- /dev/null
@@ -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();
+}