public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/108990] New: Too restrictive precision check in fold and simplify pattern for PR70920
@ 2023-03-02 13:49 hubicka at gcc dot gnu.org
  2023-03-02 23:21 ` [Bug middle-end/108990] " pinskia at gcc dot gnu.org
  2023-03-03  8:21 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-03-02 13:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108990

            Bug ID: 108990
           Summary: Too restrictive precision check in fold and simplify
                    pattern for PR70920
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

While experimenting with a new gimple pass we noticed that pr70920.c is
sensitive on order of substitutions made.  If 0 is propagated first into if
stmt, match and simplify fails to simplify the conditional since it compares
pointer type 0 with integer converted to pointer type.
TYPE_PRECISION of int is 32.

(for cmp (ne eq)
 (simplify
  (cmp (convert @0) INTEGER_CST@1)
  (if (((POINTER_TYPE_P (TREE_TYPE (@0))
         && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@0)))
         && INTEGRAL_TYPE_P (TREE_TYPE (@1))
         /* Don't perform this optimization in GENERIC if @0 has reference
            type when sanitizing.  See PR101210.  */
         && !(GENERIC
              && TREE_CODE (TREE_TYPE (@0)) == REFERENCE_TYPE
              && (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))))
        || (INTEGRAL_TYPE_P (TREE_TYPE (@0))
            && POINTER_TYPE_P (TREE_TYPE (@1))
            && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (TREE_TYPE (@1)))))
       && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
   (cmp @0 (convert @1)))))

So last conditional is false (32 and 64)

In this adjusted testcase:
#include <stdint.h>

void f1();
void f2();

void
foo (int a)
{
  int *b = (int *)a;
  if (b == (void *)0)
    {
      f1 ();
    }
}

the unnecessary cast survives to forwprop while it chould be caught by cpp1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-03  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 13:49 [Bug middle-end/108990] New: Too restrictive precision check in fold and simplify pattern for PR70920 hubicka at gcc dot gnu.org
2023-03-02 23:21 ` [Bug middle-end/108990] " pinskia at gcc dot gnu.org
2023-03-03  8:21 ` rguenth at gcc dot gnu.org

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