if (TREE_CODE (offset) != SSA_NAME)
return false;
- /* Get the defining statement of the offset before type
- conversion. */
- offset = SSA_NAME_DEF_STMT (offset);
+ /* Try to find an expression for a proper index. This is either
+ a multiplication expression by the element size or just the
+ ssa name we came along in case the element size is one. */
+ if (integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (lhs)))))
+ index = offset;
+ else
+ {
+ offset = SSA_NAME_DEF_STMT (offset);
- /* The statement which defines OFFSET before type conversion
- must be a simple GIMPLE_MODIFY_STMT. */
- if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT)
- return false;
+ /* The RHS of the statement which defines OFFSET must be a
+ multiplication of an object by the size of the array elements. */
+ if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT)
+ return false;
- /* The RHS of the statement which defines OFFSET must be a
- multiplication of an object by the size of the array elements.
- This implicitly verifies that the size of the array elements
- is constant. */
- offset = GIMPLE_STMT_OPERAND (offset, 1);
- if (TREE_CODE (offset) != MULT_EXPR
- || TREE_CODE (TREE_OPERAND (offset, 1)) != INTEGER_CST
- || !simple_cst_equal (TREE_OPERAND (offset, 1),
- TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (lhs)))))
- return false;
+ offset = GIMPLE_STMT_OPERAND (offset, 1);
+ if (TREE_CODE (offset) != MULT_EXPR
+ || TREE_CODE (TREE_OPERAND (offset, 1)) != INTEGER_CST
+ || !simple_cst_equal (TREE_OPERAND (offset, 1),
+ TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (lhs)))))
+ return false;
- /* The first operand to the MULT_EXPR is the desired index. */
- index = TREE_OPERAND (offset, 0);
+ /* The first operand to the MULT_EXPR is the desired index. */
+ index = TREE_OPERAND (offset, 0);
+ }
/* Replace the pointer addition with array indexing. */
GIMPLE_STMT_OPERAND (use_stmt, 1) = unshare_expr (def_rhs);