This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/31136] [4.2 Regression] FRE ignores bit-field truncation (C and C++ front-end don't produce bit-field truncation
- From: "spark at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Mar 2007 05:01:00 -0000
- Subject: [Bug tree-optimization/31136] [4.2 Regression] FRE ignores bit-field truncation (C and C++ front-end don't produce bit-field truncation
- References: <bug-31136-12896@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #7 from spark at gcc dot gnu dot org 2007-03-23 05:00 -------
Follow up on Joseph's analysis:
The problematic STRIP_SIGN_NOPS() call is from fold_unary()
which is called from try_combine_conversion() in tree-ssa-pre.c.
STRIP_SIGN_NOPS() is called with the expression:
<nop_expr 0x866f220
type <integer_type 0xf7e30678 public unsigned QI
size <integer_cst 0xf7d781e0 constant invariant 8>
unit size <integer_cst 0xf7d781f8 constant invariant 1>
align 8 symtab 0 alias set -1 precision 4 min <integer_cst 0xf7e32618
0> max <integer_cst 0xf7e32630 15>>
arg 0 <integer_cst 0xf7e327b0 type <integer_type 0xf7e306d4> constant
invariant 31>>
and it stripes away the conversion,
leaving only integer constant 31.
This is clearly wrong as it removes the downconversion of precision.
Following patch (against 4.2 branch) seems to fix the problem:
Index: tree.h
===================================================================
--- tree.h (revision 123088)
+++ tree.h (working copy)
@@ -912,7 +912,9 @@ extern void omp_clause_range_check_faile
&& (TYPE_MODE (TREE_TYPE (EXP)) \
== TYPE_MODE (TREE_TYPE (TREE_OPERAND (EXP, 0)))) \
&& (TYPE_UNSIGNED (TREE_TYPE (EXP)) \
- == TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (EXP, 0))))) \
+ == TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (EXP, 0))))\
+ && (TYPE_PRECISION (TREE_TYPE (EXP)) \
+ >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (EXP, 0)))))\
(EXP) = TREE_OPERAND (EXP, 0)
/* Like STRIP_NOPS, but don't alter the TREE_TYPE either. */
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31136