public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] PR tree-optimization/105597 - Check operand for type, not LHS.
@ 2022-05-13 18:41 Andrew MacLeod
  0 siblings, 0 replies; only message in thread
From: Andrew MacLeod @ 2022-05-13 18:41 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

Earlier patch was picking the type of the expression in a minus 
operation from the LHS.   When we are folding, the LHS may not be 
defined yet.

Instead, pick up the type from operand 1, and ensure it isn't undefined 
while we're at it.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew

[-- Attachment #2: 597.patch --]
[-- Type: text/x-patch, Size: 1939 bytes --]

commit e97e99296505e6015bc9e281364818bb89ca8a49
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Fri May 13 13:11:18 2022 -0400

    Check operand for type, not LHS.
    
    When folding, the LHS has not been set, so we should be checking the type of
    op1.  We should also make sure op1 is not undefined.
    
            PR tree-optimization/105597
            gcc/
            * range-op.cc (operator_minus::lhs_op1_relation): Use op1 instead
            of the lhs and make sure it is not undefined.
            gcc/testsuite/
            * gcc.dg/pr105597.c: New.

diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index e6b32e288b0..c88da8caa6c 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -1343,10 +1343,10 @@ operator_minus::wi_fold (irange &r, tree type,
 // OP1 and OP2.
 
 relation_kind
-operator_minus::lhs_op1_relation (const irange &lhs, const irange &,
+operator_minus::lhs_op1_relation (const irange &, const irange &op1,
 				  const irange &, relation_kind rel) const
 {
-  if (TYPE_SIGN (lhs.type ()) == UNSIGNED)
+  if (!op1.undefined_p () && TYPE_SIGN (op1.type ()) == UNSIGNED)
     switch (rel)
       {
       case VREL_GT:
diff --git a/gcc/testsuite/gcc.dg/pr105597.c b/gcc/testsuite/gcc.dg/pr105597.c
new file mode 100644
index 00000000000..e463ec6c194
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105597.c
@@ -0,0 +1,27 @@
+/* PR tree-optimization/105597 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wno-int-conversion" } */
+
+typedef struct {
+  int allocated;
+} vvec;
+
+int vvneeds_want, mgpssort;
+
+void vvinit(vvec *v, int minelems) { v->allocated = -minelems; }
+
+void vvneeds(vvec *v, int needed) {
+  if (needed > v->allocated)
+    if (v->allocated < 0)
+      ;
+    else {
+      int next = v->allocated + (v->allocated >> 1);
+      vvneeds_want = next;
+    }
+}
+
+void mgpssort_1() {
+  vvinit((vvec *) &mgpssort, mgpssort_1);
+  vvneeds((vvec *) &mgpssort, mgpssort_1);
+}
+

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

only message in thread, other threads:[~2022-05-13 18:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 18:41 [COMMITTED] PR tree-optimization/105597 - Check operand for type, not LHS Andrew MacLeod

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