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