This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
generic bug in fixed-point constant folding
- From: "Sean D'Epagnier" <geckosenator at gmail dot com>
- To: "Fu, Chao-Ying" <fu at mips dot com>, gcc at gcc dot gnu dot org
- Date: Mon, 16 Mar 2009 21:17:18 -0600
- Subject: generic bug in fixed-point constant folding
Hi,
I think I found a generic problem for fixed point constant folding.
In fold-const.c:11872 gcc tries to apply:
/* Transform (x >> c) << c into x & (-1<<c), or transform (x <<
c) >> c
into x & ((unsigned)-1 >> c) for unsigned types. */
I attached a simple patch which fixes the problem by not applying this
optimization to fixed point types. I would like to have this
optimization because it is possible.. but the problem is fixed-point
types do not support bitwise operations like & | ^ ~.. so without
supporting these somehow internally but not allowing the user to have
them, this can't take place.
I am open to other suggestions. For future reference should this be
posted as a bug report? It seems simple enough that it could be
included right away.. but I feel like if it's a bug report no one will
notice since fixed-point support is not widely used.
Sean
Index: fold-const.c
===================================================================
--- fold-const.c (revision 144210)
+++ fold-const.c (working copy)
@@ -11877,7 +11877,8 @@ fold_binary (enum tree_code code, tree t
&& host_integerp (arg1, false)
&& TREE_INT_CST_LOW (arg1) < TYPE_PRECISION (type)
&& host_integerp (TREE_OPERAND (arg0, 1), false)
- && TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < TYPE_PRECISION (type))
+ && TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < TYPE_PRECISION (type)
+ && TREE_CODE (type) != FIXED_POINT_TYPE)
{
HOST_WIDE_INT low0 = TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1));
HOST_WIDE_INT low1 = TREE_INT_CST_LOW (arg1);