===================================================================
@@ -624,6 +624,10 @@ copy_reference_ops_from_ref (tree ref, V
switch (temp.opcode)
{
+ case WITH_SIZE_EXPR:
+ temp.op0 = TREE_OPERAND (ref, 1);
+ temp.off = 0;
+ break;
case MEM_REF:
/* The base address gets its own vn_reference_op_s structure. */
temp.op0 = TREE_OPERAND (ref, 1);
@@ -740,6 +744,7 @@ copy_reference_ops_from_ref (tree ref, V
VEC_safe_push (vn_reference_op_s, heap, *result, &temp);
if (REFERENCE_CLASS_P (ref)
+ || TREE_CODE (ref) == WITH_SIZE_EXPR
|| (TREE_CODE (ref) == ADDR_EXPR
&& !is_gimple_min_invariant (ref)))
ref = TREE_OPERAND (ref, 0);
===================================================================
@@ -2792,6 +2792,23 @@ create_component_ref_by_pieces_1 (basic_
return folded;
}
break;
+ case WITH_SIZE_EXPR:
+ {
+ tree genop0 = create_component_ref_by_pieces_1 (block, ref, operand,
+ stmts, domstmt);
+ pre_expr op1expr = get_or_alloc_expr_for (currop->op0);
+ tree genop1;
+
+ if (!genop0)
+ return NULL_TREE;
+
+ genop1 = find_or_generate_expression (block, op1expr, stmts, domstmt);
+ if (!genop1)
+ return NULL_TREE;
+
+ return fold_build2 (currop->opcode, currop->type, genop0, genop1);
+ }
+ break;
case BIT_FIELD_REF:
{
tree folded;
===================================================================
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int
+zzz (char *s1, char *s2, int len, int *q)
+{
+ int z = 5;
+ unsigned int i, b;
+ struct s { char a[z]; };
+ struct s x;
+
+ extern int foo (int, ...) __attribute__((pure));
+
+ for (i = 0; i < len; i++)
+ s1[i] = s2[i];
+
+ b = z & 0x3;
+
+ len += (b == 0 ? 0 : 1) + z;
+
+ *q = len;
+ return foo (z, x, x);
+}
===================================================================
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int y;
+extern int foo (int, ...) __attribute__((pure));
+
+int
+zzz (char *s1, char *s2, int len, int *q, int c)
+{
+ int z = 5;
+ unsigned int i, b;
+ struct s { char a[z]; };
+ struct s x;
+ int y_tmp = 5;
+
+ for (i = 0; i < len; i++)
+ s1[i] = s2[i];
+
+ b = z & 0x3;
+
+ len += (b == 0 ? 0 : 1) + z;
+
+ *q = len;
+
+ if (c)
+ y_tmp = foo (z, x, x) + 4;
+
+ z = foo (z, x, x) + 4;
+ y = y_tmp;
+
+ return z;
+}