&& (sym = TREE_OPERAND (TREE_OPERAND (*tp, 0), 0))
&& DECL_P (sym)
&& !TREE_ADDRESSABLE (sym)
- && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym)))
+ && bitmap_bit_p (suitable_for_renaming, DECL_UID (sym))
+ && is_gimple_reg_type (TREE_TYPE (*tp))
+ && ! VOID_TYPE_P (TREE_TYPE (*tp)))
{
if (TREE_CODE (TREE_TYPE (sym)) == VECTOR_TYPE
&& useless_type_conversion_p (TREE_TYPE (*tp),
? REALPART_EXPR : IMAGPART_EXPR,
TREE_TYPE (*tp), sym);
}
- else if (integer_zerop (TREE_OPERAND (*tp, 1)))
+ else if (integer_zerop (TREE_OPERAND (*tp, 1))
+ && DECL_SIZE (sym) == TYPE_SIZE (TREE_TYPE (*tp)))
{
if (!useless_type_conversion_p (TREE_TYPE (*tp),
TREE_TYPE (sym)))
else
*tp = sym;
}
+ else if (DECL_SIZE (sym)
+ && TREE_CODE (DECL_SIZE (sym)) == INTEGER_CST
+ && mem_ref_offset (*tp) >= 0
+ && wi::leu_p (mem_ref_offset (*tp)
+ + wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (*tp))),
+ wi::to_offset (DECL_SIZE_UNIT (sym)))
+ && (! INTEGRAL_TYPE_P (TREE_TYPE (*tp))
+ || (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp)))
+ == TYPE_PRECISION (TREE_TYPE (*tp))))
+ && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (*tp))),
+ BITS_PER_UNIT) == 0)
+ {
+ *tp = build3 (BIT_FIELD_REF, TREE_TYPE (*tp), sym,
+ TYPE_SIZE (TREE_TYPE (*tp)),
+ wide_int_to_tree (bitsizetype,
+ mem_ref_offset (*tp)
+ << LOG2_BITS_PER_UNIT));
+ }
}
}
&& TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
{
tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
+ if (! DECL_P (decl))
+ return NULL_TREE;
+ if (! is_gimple_reg_type (TREE_TYPE (base))
+ || VOID_TYPE_P (TREE_TYPE (base)))
+ return decl;
if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
|| TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
&& useless_type_conversion_p (TREE_TYPE (base),
&& multiple_of_p (sizetype, TREE_OPERAND (base, 1),
TYPE_SIZE_UNIT (TREE_TYPE (base))))
return NULL_TREE;
- if (DECL_P (decl)
- && (!integer_zerop (TREE_OPERAND (base, 1))
- || (DECL_SIZE (decl)
- != TYPE_SIZE (TREE_TYPE (base)))
- || TREE_THIS_VOLATILE (decl) != TREE_THIS_VOLATILE (base)))
- return decl;
+ /* For same sizes and zero offset we can use a VIEW_CONVERT_EXPR. */
+ if (integer_zerop (TREE_OPERAND (base, 1))
+ && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (base)))
+ return NULL_TREE;
+ /* For integral typed extracts we can use a BIT_FIELD_REF. */
+ if (DECL_SIZE (decl)
+ && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
+ && mem_ref_offset (base) >= 0
+ && wi::leu_p (mem_ref_offset (base)
+ + wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (base))),
+ wi::to_offset (DECL_SIZE_UNIT (decl)))
+ /* ??? We can't handle bitfield precision extracts without
+ either using an alternate type for the BIT_FIELD_REF and
+ then doing a conversion or possibly adjusting the offset
+ according to endianess. */
+ && (! INTEGRAL_TYPE_P (TREE_TYPE (base))
+ || (wi::to_offset (TYPE_SIZE (TREE_TYPE (base)))
+ == TYPE_PRECISION (TREE_TYPE (base))))
+ && wi::umod_trunc (wi::to_offset (TYPE_SIZE (TREE_TYPE (base))),
+ BITS_PER_UNIT) == 0)
+ return NULL_TREE;
+ return decl;
}
return NULL_TREE;