diff options
author | Xi Ruoyao <xry111@xry111.site> | 2025-03-01 11:46:44 +0800 |
---|---|---|
committer | Lulu Cheng <chenglulu@loongson.cn> | 2025-08-18 09:09:34 +0800 |
commit | 91f00a75536a553b5f95ea80694d655c5ddf34af (patch) | |
tree | 6520095b139a1dce80733e0fc45ec0693d1c2c02 | |
parent | d1d7ecfbc6d86f660ec79ca272b20aea9d6c3ca7 (diff) | |
download | gcc-91f00a75536a553b5f95ea80694d655c5ddf34af.zip gcc-91f00a75536a553b5f95ea80694d655c5ddf34af.tar.gz gcc-91f00a75536a553b5f95ea80694d655c5ddf34af.tar.bz2 |
LoongArch: Allow using bstrins for masking the address in atomic_test_and_set
We can use bstrins for masking the address here. As people are already
working on LA32R (which lacks bstrins instructions), for future-proofing
we check whether (const_int -4) is an and_operand and force it into an
register if not.
gcc/ChangeLog:
* config/loongarch/sync.md (atomic_test_and_set): Use bstrins
for masking the address if possible.
-rw-r--r-- | gcc/config/loongarch/sync.md | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/gcc/config/loongarch/sync.md b/gcc/config/loongarch/sync.md index 63929ab..01346a7 100644 --- a/gcc/config/loongarch/sync.md +++ b/gcc/config/loongarch/sync.md @@ -356,12 +356,13 @@ rtx mem = operands[1]; rtx model = operands[2]; rtx addr = force_reg (Pmode, XEXP (mem, 0)); - rtx tmp_reg = gen_reg_rtx (Pmode); - rtx zero_reg = gen_rtx_REG (Pmode, 0); - + rtx mask = gen_int_mode (-4, Pmode); rtx aligned_addr = gen_reg_rtx (Pmode); - emit_move_insn (tmp_reg, gen_rtx_PLUS (Pmode, zero_reg, GEN_INT (-4))); - emit_move_insn (aligned_addr, gen_rtx_AND (Pmode, addr, tmp_reg)); + + if (!and_operand (mask, Pmode)) + mask = force_reg (Pmode, mask); + + emit_move_insn (aligned_addr, gen_rtx_AND (Pmode, addr, mask)); rtx aligned_mem = change_address (mem, SImode, aligned_addr); set_mem_alias_set (aligned_mem, 0); |