Don't simplify (A & C) != 0 ? D : 0 for pointer types.

While rewriting part of PHI-OPT to use match-and-simplify,
I ran into a bug where this pattern in match.pd would hit
and would produce invalid gimple; a shift of a pointer type.

This just disables this simplification for pointer types similarly
to what is already done in PHI-OPT for the generic A ? D : 0 case.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

2021-5-23  Andrew Pinski  <apinski@marvell.com>

gcc/
	* match.pd ((A & C) != 0 ? D : 0): Limit to non pointer types.

gcc/testsuite/
	* gcc.dg/gimplefe-45.c: New test.
This commit is contained in:
Andrew Pinski 2021-05-16 10:40:16 -07:00
parent 15d30d2f20
commit 99b76adb94
2 changed files with 20 additions and 1 deletions

View File

@ -4840,7 +4840,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cond
(ne (bit_and @0 integer_pow2p@1) integer_zerop)
INTEGER_CST@2 integer_zerop)
(if (integer_pow2p (@2))
(if (!POINTER_TYPE_P (type) && integer_pow2p (@2))
(with {
int shift = (wi::exact_log2 (wi::to_wide (@2))
- wi::exact_log2 (wi::to_wide (@1)));

View File

@ -0,0 +1,19 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fgimple" } */
/* This used to ICE when simplifying (A & C) != 0 ? D : 0
for pointer types. */
int *__GIMPLE ()
p (int n)
{
int *_2;
int *_t;
int *_t1;
_t = (int*)8;
_t1 = 0;
n = n & 2;
_2 = n != 0 ? _t : _t1;
return _2;
}