https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122635
--- Comment #11 from Robin Dapp <rdapp at gcc dot gnu.org> ---
As mentioned in #2 dse can do it. It probably can be done in other places as
well but it doesn't feel very out of place in dse either:
diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index 51a572316cd..119b5c6c319 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -164,7 +164,7 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write,
bool may_def_ok = false)
internal_fn ifn = gimple_call_internal_fn (stmt);
int stored_value_index = internal_fn_stored_value_index (ifn);
int len_index = internal_fn_len_index (ifn);
- if (ifn == IFN_LEN_STORE)
+ if (ifn == IFN_LEN_STORE || ifn == IFN_MASK_LEN_STORE)
{
tree len = gimple_call_arg (stmt, len_index);
tree bias = gimple_call_arg (stmt, len_index + 1);
@@ -1568,8 +1568,29 @@ dse_optimize_stmt (function *fun, gimple_stmt_iterator
*gsi, sbitmap live_bytes)
switch (gimple_call_internal_fn (stmt))
{
case IFN_LEN_STORE:
- case IFN_MASK_STORE:
case IFN_MASK_LEN_STORE:
+ {
+ internal_fn ifn = gimple_call_internal_fn (stmt);
+ int len_index = internal_fn_len_index (ifn);
+ tree len = gimple_call_arg (stmt, len_index);
+ tree bias = gimple_call_arg (stmt, len_index + 1);
+
+ if (tree_fits_uhwi_p (len) && tree_fits_shwi_p (bias))
+ {
+ HOST_WIDE_INT len_val = tree_to_shwi (len);
+ HOST_WIDE_INT bias_val = tree_to_uhwi (bias);
+ if (len_val + bias_val <= 0)
+ {
+ delete_dead_or_redundant_call (gsi, "dead");
+ return;
+ }
+ }
+ /* FALLTHRU */
+ }
+ case IFN_MASK_STORE:
{
enum dse_store_status store_status;
store_status = dse_classify_store (&ref, stmt, false, live_bytes);