diff options
author | Adam Nemet <anemet@caviumnetworks.com> | 2009-06-17 22:11:47 +0000 |
---|---|---|
committer | Adam Nemet <nemet@gcc.gnu.org> | 2009-06-17 22:11:47 +0000 |
commit | 23314e77ec9e3dfea806f31b6dd65920f628f207 (patch) | |
tree | 891864d93af2879f6eb0fac88b1eb64c1454dc24 /gcc/tree.c | |
parent | 799dbb0f77a506ed18a17ac3765b29af9dd88055 (diff) | |
download | gcc-23314e77ec9e3dfea806f31b6dd65920f628f207.zip gcc-23314e77ec9e3dfea806f31b6dd65920f628f207.tar.gz gcc-23314e77ec9e3dfea806f31b6dd65920f628f207.tar.bz2 |
tree.h (STRIP_NOPS, [...]): Use tree_strip_nop_conversions...
* tree.h (STRIP_NOPS, STRIP_SIGN_NOPS,
STRIP_USELESS_TYPE_CONVERSION): Use tree_strip_nop_conversions,
tree_strip_sign_nop_conversions and
tree_ssa_strip_useless_type_conversions rather than stripping
the operations here.
(tree_strip_nop_conversions, tree_strip_sign_nop_conversions):
Declare them.
* gimple.h (tree_ssa_strip_useless_type_conversions): Declare it.
* tree-ssa.c (tree_ssa_strip_useless_type_conversions): New function.
* tree.c (tree_nop_conversion, tree_sign_nop_conversion,
tree_strip_nop_conversions, tree_strip_sign_nop_conversions): New
functions.
testsuite/
* gcc.c-torture/execute/bitfld-5.c: New test.
From-SVN: r148631
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 73 |
1 files changed, 73 insertions, 0 deletions
@@ -9460,5 +9460,78 @@ list_equal_p (const_tree t1, const_tree t2) return !t1 && !t2; } +/* Return true iff conversion in EXP generates no instruction. Mark + it inline so that we fully inline into the stripping functions even + though we have two uses of this function. */ + +static inline bool +tree_nop_conversion (const_tree exp) +{ + tree outer_type, inner_type; + + if (!CONVERT_EXPR_P (exp) + && TREE_CODE (exp) != NON_LVALUE_EXPR) + return false; + if (TREE_OPERAND (exp, 0) == error_mark_node) + return false; + + outer_type = TREE_TYPE (exp); + inner_type = TREE_TYPE (TREE_OPERAND (exp, 0)); + + /* Use precision rather then machine mode when we can, which gives + the correct answer even for submode (bit-field) types. */ + if ((INTEGRAL_TYPE_P (outer_type) + || POINTER_TYPE_P (outer_type) + || TREE_CODE (outer_type) == OFFSET_TYPE) + && (INTEGRAL_TYPE_P (inner_type) + || POINTER_TYPE_P (inner_type) + || TREE_CODE (inner_type) == OFFSET_TYPE)) + return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type); + + /* Otherwise fall back on comparing machine modes (e.g. for + aggregate types, floats). */ + return TYPE_MODE (outer_type) == TYPE_MODE (inner_type); +} + +/* Return true iff conversion in EXP generates no instruction. Don't + consider conversions changing the signedness. */ + +static bool +tree_sign_nop_conversion (const_tree exp) +{ + tree outer_type, inner_type; + + if (!tree_nop_conversion (exp)) + return false; + + outer_type = TREE_TYPE (exp); + inner_type = TREE_TYPE (TREE_OPERAND (exp, 0)); + + return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type) + && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type)); +} + +/* Strip conversions from EXP according to tree_nop_conversion and + return the resulting expression. */ + +tree +tree_strip_nop_conversions (tree exp) +{ + while (tree_nop_conversion (exp)) + exp = TREE_OPERAND (exp, 0); + return exp; +} + +/* Strip conversions from EXP according to tree_sign_nop_conversion + and return the resulting expression. */ + +tree +tree_strip_sign_nop_conversions (tree exp) +{ + while (tree_sign_nop_conversion (exp)) + exp = TREE_OPERAND (exp, 0); + return exp; +} + #include "gt-tree.h" |