summaryrefslogtreecommitdiff
path: root/gcc/flow.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2001-12-04 09:33:17 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2001-12-04 09:33:17 +0000
commit0e06376ed7e8e683eda17067bb305b0aefc30d9d (patch)
treef4cbf2a19a8962de46bab2e668b5770fcd6f9668 /gcc/flow.c
parentd06f5fba02544a6918059089574c3dfc4c01e2c6 (diff)
downloadgcc-0e06376ed7e8e683eda17067bb305b0aefc30d9d.tar.gz
* flow.c (ior_reg_cond): Return NULL if ! add and rtx wasn't optimized.
Return correct value if one of the subexpressions was optimized to 0 resp. 1. Optimize (x | A) | x and (x & A) | x. (and_reg_cond): Similarly. * gcc.c-torture/compile/20011130-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@47602 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/flow.c')
-rw-r--r--gcc/flow.c113
1 files changed, 63 insertions, 50 deletions
diff --git a/gcc/flow.c b/gcc/flow.c
index df27edc8f45..fdf4df29b1b 100644
--- a/gcc/flow.c
+++ b/gcc/flow.c
@@ -2796,7 +2796,7 @@ flush_reg_cond_reg (pbi, regno)
For ior/and, the ADD flag determines whether we want to add the new
condition X to the old one unconditionally. If it is zero, we will
only return a new expression if X allows us to simplify part of
- OLD, otherwise we return OLD unchanged to the caller.
+ OLD, otherwise we return NULL to the caller.
If ADD is nonzero, we will return a new condition in all cases. The
toplevel caller of one of these functions should always pass 1 for
ADD. */
@@ -2818,7 +2818,7 @@ ior_reg_cond (old, x, add)
&& REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
return old;
if (! add)
- return old;
+ return NULL;
return gen_rtx_IOR (0, old, x);
}
@@ -2827,51 +2827,63 @@ ior_reg_cond (old, x, add)
case IOR:
op0 = ior_reg_cond (XEXP (old, 0), x, 0);
op1 = ior_reg_cond (XEXP (old, 1), x, 0);
- if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
+ if (op0 != NULL || op1 != NULL)
{
if (op0 == const0_rtx)
- return op1;
+ return op1 ? op1 : gen_rtx_IOR (0, XEXP (old, 1), x);
if (op1 == const0_rtx)
- return op0;
+ return op0 ? op0 : gen_rtx_IOR (0, XEXP (old, 0), x);
if (op0 == const1_rtx || op1 == const1_rtx)
return const1_rtx;
- if (op0 == XEXP (old, 0))
- op0 = gen_rtx_IOR (0, op0, x);
- else
- op1 = gen_rtx_IOR (0, op1, x);
+ if (op0 == NULL)
+ op0 = gen_rtx_IOR (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x | A) | x ~ (x | A). */
+ return old;
+ if (op1 == NULL)
+ op1 = gen_rtx_IOR (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A | x) | x ~ (A | x). */
+ return old;
return gen_rtx_IOR (0, op0, op1);
}
if (! add)
- return old;
+ return NULL;
return gen_rtx_IOR (0, old, x);
case AND:
op0 = ior_reg_cond (XEXP (old, 0), x, 0);
op1 = ior_reg_cond (XEXP (old, 1), x, 0);
- if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
+ if (op0 != NULL || op1 != NULL)
{
if (op0 == const1_rtx)
- return op1;
+ return op1 ? op1 : gen_rtx_IOR (0, XEXP (old, 1), x);
if (op1 == const1_rtx)
- return op0;
+ return op0 ? op0 : gen_rtx_IOR (0, XEXP (old, 0), x);
if (op0 == const0_rtx || op1 == const0_rtx)
return const0_rtx;
- if (op0 == XEXP (old, 0))
- op0 = gen_rtx_IOR (0, op0, x);
- else
- op1 = gen_rtx_IOR (0, op1, x);
+ if (op0 == NULL)
+ op0 = gen_rtx_IOR (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x & A) | x ~ x. */
+ return op0;
+ if (op1 == NULL)
+ op1 = gen_rtx_IOR (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A & x) | x ~ x. */
+ return op1;
return gen_rtx_AND (0, op0, op1);
}
if (! add)
- return old;
+ return NULL;
return gen_rtx_IOR (0, old, x);
case NOT:
op0 = and_reg_cond (XEXP (old, 0), not_reg_cond (x), 0);
- if (op0 != XEXP (old, 0))
+ if (op0 != NULL)
return not_reg_cond (op0);
if (! add)
- return old;
+ return NULL;
return gen_rtx_IOR (0, old, x);
default:
@@ -2921,7 +2933,7 @@ and_reg_cond (old, x, add)
&& REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
return old;
if (! add)
- return old;
+ return NULL;
return gen_rtx_AND (0, old, x);
}
@@ -2930,62 +2942,63 @@ and_reg_cond (old, x, add)
case IOR:
op0 = and_reg_cond (XEXP (old, 0), x, 0);
op1 = and_reg_cond (XEXP (old, 1), x, 0);
- if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
+ if (op0 != NULL || op1 != NULL)
{
if (op0 == const0_rtx)
- return op1;
+ return op1 ? op1 : gen_rtx_AND (0, XEXP (old, 1), x);
if (op1 == const0_rtx)
- return op0;
+ return op0 ? op0 : gen_rtx_AND (0, XEXP (old, 0), x);
if (op0 == const1_rtx || op1 == const1_rtx)
return const1_rtx;
- if (op0 == XEXP (old, 0))
- op0 = gen_rtx_AND (0, op0, x);
- else
- op1 = gen_rtx_AND (0, op1, x);
+ if (op0 == NULL)
+ op0 = gen_rtx_AND (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x | A) & x ~ x. */
+ return op0;
+ if (op1 == NULL)
+ op1 = gen_rtx_AND (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A | x) & x ~ x. */
+ return op1;
return gen_rtx_IOR (0, op0, op1);
}
if (! add)
- return old;
+ return NULL;
return gen_rtx_AND (0, old, x);
case AND:
op0 = and_reg_cond (XEXP (old, 0), x, 0);
op1 = and_reg_cond (XEXP (old, 1), x, 0);
- if (op0 != XEXP (old, 0) || op1 != XEXP (old, 1))
+ if (op0 != NULL || op1 != NULL)
{
if (op0 == const1_rtx)
- return op1;
+ return op1 ? op1 : gen_rtx_AND (0, XEXP (old, 1), x);
if (op1 == const1_rtx)
- return op0;
+ return op0 ? op0 : gen_rtx_AND (0, XEXP (old, 0), x);
if (op0 == const0_rtx || op1 == const0_rtx)
return const0_rtx;
- if (op0 == XEXP (old, 0))
- op0 = gen_rtx_AND (0, op0, x);
- else
- op1 = gen_rtx_AND (0, op1, x);
+ if (op0 == NULL)
+ op0 = gen_rtx_AND (0, XEXP (old, 0), x);
+ else if (rtx_equal_p (x, op0))
+ /* (x & A) & x ~ (x & A). */
+ return old;
+ if (op1 == NULL)
+ op1 = gen_rtx_AND (0, XEXP (old, 1), x);
+ else if (rtx_equal_p (x, op1))
+ /* (A & x) & x ~ (A & x). */
+ return old;
return gen_rtx_AND (0, op0, op1);
}
if (! add)
- return old;
-
- /* If X is identical to one of the existing terms of the AND,
- then just return what we already have. */
- /* ??? There really should be some sort of recursive check here in
- case there are nested ANDs. */
- if ((GET_CODE (XEXP (old, 0)) == GET_CODE (x)
- && REGNO (XEXP (XEXP (old, 0), 0)) == REGNO (XEXP (x, 0)))
- || (GET_CODE (XEXP (old, 1)) == GET_CODE (x)
- && REGNO (XEXP (XEXP (old, 1), 0)) == REGNO (XEXP (x, 0))))
- return old;
-
+ return NULL;
return gen_rtx_AND (0, old, x);
case NOT:
op0 = ior_reg_cond (XEXP (old, 0), not_reg_cond (x), 0);
- if (op0 != XEXP (old, 0))
+ if (op0 != NULL)
return not_reg_cond (op0);
if (! add)
- return old;
+ return NULL;
return gen_rtx_AND (0, old, x);
default: