+2017-10-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/82434
+ * fold-const.h (can_native_encode_type_p,
+ can_native_encode_string_p): Remove.
+ * fold-const.c (native_encode_int): Formatting fixes. If ptr is NULL,
+ don't encode anything, just return what would be otherwise returned.
+ (native_encode_fixed, native_encode_complex, native_encode_vector):
+ Likewise.
+ (native_encode_string): Likewise. Inline by hand
+ can_native_encode_string_p.
+ (can_native_encode_type_p): Remove.
+ (can_native_encode_string_p): Remove.
+ * tree-vect-stmts.c (vectorizable_store): Instead of testing just
+ STRING_CSTs using can_native_encode_string_p, test all
+ CONSTANT_CLASS_P values using native_encode_expr with NULL ptr.
+ * gimple-ssa-store-merging.c (encode_tree_to_bitpos): Remove last
+ argument from native_encode_expr.
+ (rhs_valid_for_store_merging_p): Use native_encode_expr with NULL ptr.
+ (pass_store_merging::execute): Don't unnecessarily look for 3 stmts,
+ but just 2.
+
2017-10-06 Richard Biener <rguenther@suse.de>
PR tree-optimization/82397
int byte, offset, word, words;
unsigned char value;
- if ((off == -1 && total_bytes > len)
- || off >= total_bytes)
+ if ((off == -1 && total_bytes > len) || off >= total_bytes)
return 0;
if (off == -1)
off = 0;
+
+ if (ptr == NULL)
+ /* Dry run. */
+ return MIN (len, total_bytes - off);
+
words = total_bytes / UNITS_PER_WORD;
for (byte = 0; byte < total_bytes; byte++)
}
else
offset = BYTES_BIG_ENDIAN ? (total_bytes - 1) - byte : byte;
- if (offset >= off
- && offset - off < len)
+ if (offset >= off && offset - off < len)
ptr[offset - off] = value;
}
return MIN (len, total_bytes - off);
i_type = lang_hooks.types.type_for_size (GET_MODE_BITSIZE (mode), 1);
- if (NULL_TREE == i_type
- || TYPE_PRECISION (i_type) != total_bytes)
+ if (NULL_TREE == i_type || TYPE_PRECISION (i_type) != total_bytes)
return 0;
value = TREE_FIXED_CST (expr);
up to 192 bits. */
long tmp[6];
- if ((off == -1 && total_bytes > len)
- || off >= total_bytes)
+ if ((off == -1 && total_bytes > len) || off >= total_bytes)
return 0;
if (off == -1)
off = 0;
+
+ if (ptr == NULL)
+ /* Dry run. */
+ return MIN (len, total_bytes - off);
+
words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
real_to_target (tmp, TREE_REAL_CST_PTR (expr), TYPE_MODE (type));
part = TREE_REALPART (expr);
rsize = native_encode_expr (part, ptr, len, off);
- if (off == -1
- && rsize == 0)
+ if (off == -1 && rsize == 0)
return 0;
part = TREE_IMAGPART (expr);
if (off != -1)
off = MAX (0, off - GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (part))));
- isize = native_encode_expr (part, ptr+rsize, len-rsize, off);
- if (off == -1
- && isize != rsize)
+ isize = native_encode_expr (part, ptr ? ptr + rsize : NULL,
+ len - rsize, off);
+ if (off == -1 && isize != rsize)
return 0;
return rsize + isize;
}
continue;
}
elem = VECTOR_CST_ELT (expr, i);
- int res = native_encode_expr (elem, ptr+offset, len-offset, off);
- if ((off == -1 && res != size)
- || res == 0)
+ int res = native_encode_expr (elem, ptr ? ptr + offset : NULL,
+ len - offset, off);
+ if ((off == -1 && res != size) || res == 0)
return 0;
offset += res;
if (offset >= len)
static int
native_encode_string (const_tree expr, unsigned char *ptr, int len, int off)
{
- if (! can_native_encode_string_p (expr))
+ tree type = TREE_TYPE (expr);
+
+ /* Wide-char strings are encoded in target byte-order so native
+ encoding them is trivial. */
+ if (BITS_PER_UNIT != CHAR_BIT
+ || TREE_CODE (type) != ARRAY_TYPE
+ || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
+ || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type)))
return 0;
HOST_WIDE_INT total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (expr)));
- if ((off == -1 && total_bytes > len)
- || off >= total_bytes)
+ if ((off == -1 && total_bytes > len) || off >= total_bytes)
return 0;
if (off == -1)
off = 0;
- if (TREE_STRING_LENGTH (expr) - off < MIN (total_bytes, len))
+ if (ptr == NULL)
+ /* Dry run. */;
+ else if (TREE_STRING_LENGTH (expr) - off < MIN (total_bytes, len))
{
int written = 0;
if (off < TREE_STRING_LENGTH (expr))
/* Subroutine of fold_view_convert_expr. Encode the INTEGER_CST,
REAL_CST, COMPLEX_CST or VECTOR_CST specified by EXPR into the
- buffer PTR of length LEN bytes. If OFF is not -1 then start
+ buffer PTR of length LEN bytes. If PTR is NULL, don't actually store
+ anything, just do a dry run. If OFF is not -1 then start
the encoding at byte offset OFF and encode at most LEN bytes.
Return the number of bytes placed in the buffer, or zero upon failure. */
}
}
-/* Return true iff a constant of type TYPE is accepted by
- native_encode_expr. */
-
-bool
-can_native_encode_type_p (tree type)
-{
- switch (TREE_CODE (type))
- {
- case INTEGER_TYPE:
- case REAL_TYPE:
- case FIXED_POINT_TYPE:
- case COMPLEX_TYPE:
- case VECTOR_TYPE:
- case POINTER_TYPE:
- return true;
- default:
- return false;
- }
-}
-
-/* Return true iff a STRING_CST S is accepted by
- native_encode_expr. */
-
-bool
-can_native_encode_string_p (const_tree expr)
-{
- tree type = TREE_TYPE (expr);
-
- /* Wide-char strings are encoded in target byte-order so native
- encoding them is trivial. */
- if (BITS_PER_UNIT != CHAR_BIT
- || TREE_CODE (type) != ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
- || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type)))
- return false;
- return true;
-}
/* Fold a VIEW_CONVERT_EXPR of a constant expression EXPR to type
TYPE at compile-time. If we're unable to perform the conversion
|| !int_mode_for_size (bitlen, 0).exists ());
if (!sub_byte_op_p)
- return (native_encode_expr (tmp_int, ptr + first_byte, total_bytes, 0)
- != 0);
+ return native_encode_expr (tmp_int, ptr + first_byte, total_bytes) != 0;
/* LITTLE-ENDIAN
We are writing a non byte-sized quantity or at a position that is not
memset (tmpbuf, '\0', byte_size);
/* The store detection code should only have allowed constants that are
accepted by native_encode_expr. */
- if (native_encode_expr (expr, tmpbuf, byte_size - 1, 0) == 0)
+ if (native_encode_expr (expr, tmpbuf, byte_size - 1) == 0)
gcc_unreachable ();
/* The native_encode_expr machinery uses TYPE_MODE to determine how many
static bool
rhs_valid_for_store_merging_p (tree rhs)
{
- tree type = TREE_TYPE (rhs);
- if (TREE_CODE_CLASS (TREE_CODE (rhs)) != tcc_constant
- || !can_native_encode_type_p (type))
- return false;
-
- return true;
+ return native_encode_expr (rhs, NULL,
+ GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (rhs)))) != 0;
}
/* Entry point for the pass. Go over each basic block recording chains of
if (is_gimple_debug (gsi_stmt (gsi)))
continue;
- if (++num_statements > 2)
+ if (++num_statements >= 2)
break;
}