[Bug tree-optimization/124667] Optimize load/store IOR|AND branch mispredict (former bitmap_set_bit from GCC benchmark)
daniel.barboza at oss dot qualcomm.com
gcc-bugzilla@gcc.gnu.org
Mon Mar 30 09:46:24 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124667
--- Comment #3 from Daniel Henrique Barboza <daniel.barboza at oss dot qualcomm.com> ---
(In reply to Andrew Pinski from comment #1)
> bool res = (ptr->bits[word_num] & bit_val) == 0;
> if (res)
> ptr->bits[word_num] |= bit_val;
>
> Converting this into:
> ptr->bits[word_num] |= bit_val;
>
> is not valid with the C11/C++11 threading model so it needs a
> `!flag_store_data_races` check. And The only other problem is if this is
> read only memory then doing the store always could cause issues too.
Right. I see these constraints are already implemented in
cond_store_replacement() (ref_can_have_store_data_races() checks for
flag_store_data_races):
/* Prove that we can move the store down. We could also check
TREE_THIS_NOTRAP here, but in that case we also could move stores,
whose value is not available readily, which we want to avoid. */
if (!nontrap->contains (lhs))
{
/* If LHS is an access to a local variable without address-taken
(or when we allow data races) and known not to trap, we could
always safely move down the store. */
tree base;
if (ref_can_have_store_data_races (lhs)
|| tree_could_trap_p (lhs)
/* tree_could_trap_p is a predicate for rvalues, so check
for readonly memory explicitly. */
|| ((base = get_base_address (lhs))
&& ((DECL_P (base)
&& TREE_READONLY (base))
|| TREE_CODE (base) == STRING_CST)))
return false;
}
I'll add these in this transformation too (maybe excluding the trap check).
More information about the Gcc-bugs
mailing list