This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
if_then_else simplification
- To: gcc-patches at gcc dot gnu dot org
- Subject: if_then_else simplification
- From: Richard Henderson <rth at cygnus dot com>
- Date: Mon, 22 May 2000 01:32:14 -0700
Consider
int f()
{
int x = 0, p;
p = foo();
if (p)
x = 1;
return x;
}
Clearly this last assignment is equivalent to
x = (p != 0);
but we currently won't transform things that far. One could argue
for stronger ifcvt in this case, but this is actually a simplification
of something in cpplib, in which foo() is actually a 5 node subgraph.
At which point things stop seeming quite so reasonable.
CSE is quite happy, however, to substitute constants such that we get
(set (reg:SI 100)
(if_then_else:SI (eq (reg:SI 101) (const_int 0))
(const_int 0)
(const_int 1)))
With this patch we take the extra step to reduce this to ne:SI.
Tested on alpha and i686, though i686 requires other changes to
get this substitution to happen. (Those secondary changes might
be a bad idea though, since they could potentially allow combine
to perform transformations that we do not want. More investigation
is required here.)
r~
* simplify-rtx.c (simplify_ternary_operation): Try to simplify
IF_THEN_ELSE to a setcc form.
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/simplify-rtx.c,v
retrieving revision 1.16
diff -c -p -d -r1.16 simplify-rtx.c
*** simplify-rtx.c 2000/05/04 21:15:03 1.16
--- simplify-rtx.c 2000/05/22 08:18:51
*************** simplify_ternary_operation (code, mode,
*** 1963,1968 ****
--- 1963,1987 ----
return op2;
else if (temp == const1_rtx)
return op1;
+ else if (temp)
+ op0 = temp;
+
+ /* Look for happy constants in op1 and op2. */
+ if (GET_CODE (op1) == CONST_INT && GET_CODE (op2) == CONST_INT)
+ {
+ HOST_WIDE_INT t = INTVAL (op1);
+ HOST_WIDE_INT f = INTVAL (op2);
+
+ if (t == STORE_FLAG_VALUE && f == 0)
+ code = GET_CODE (op0);
+ else if (t == 0 && f == STORE_FLAG_VALUE
+ && can_reverse_comparison_p (op0, NULL_RTX))
+ code = reverse_condition (GET_CODE (op0));
+ else
+ break;
+
+ return gen_rtx_fmt_ee (code, mode, XEXP (op0, 0), XEXP (op0, 1));
+ }
}
break;