Codegen fix atomic_cas with samll types on riscv64 (#5919)

* fix issue5901

* add regression test file.

* fix regression targets.

* fix a comment.

* enable atomic-cas-little for riscv64

* specify little endian some s390x can pass test.

* fix register error
This commit is contained in:
yuyang
2023-03-07 21:32:28 +08:00
committed by GitHub
parent d3fdb5fc2c
commit 812b4b5229
4 changed files with 28 additions and 10 deletions

View File

@@ -1511,7 +1511,7 @@ impl AtomicOP {
}
/// like extract but sign extend the value.
/// suitable for smax.
/// suitable for smax,etc.
pub(crate) fn extract_sext(
rd: WritableReg,
offset: Reg,

View File

@@ -1275,31 +1275,27 @@ impl MachInstEmit for Inst {
amo: AMO::SeqCst,
}
.emit(&[], sink, emit_info, state);
let origin_value = if ty.bits() < 32 {
AtomicOP::extract(t0, offset, dst.to_reg(), ty)
if ty.bits() < 32 {
AtomicOP::extract(dst, offset, dst.to_reg(), ty)
.iter()
.for_each(|i| i.emit(&[], sink, emit_info, state));
t0.to_reg()
} else if ty.bits() == 32 {
Inst::Extend {
rd: t0,
rd: dst,
rn: dst.to_reg(),
signed: false,
from_bits: 32,
to_bits: 64,
}
.emit(&[], sink, emit_info, state);
t0.to_reg()
} else {
dst.to_reg()
};
}
Inst::CondBr {
taken: BranchTarget::Label(fail_label),
not_taken: BranchTarget::zero(),
kind: IntegerCompare {
kind: IntCC::NotEqual,
rs1: e,
rs2: origin_value,
rs2: dst.to_reg(),
},
}
.emit(&[], sink, emit_info, state);

View File

@@ -1,6 +1,7 @@
test interpret
test run
target s390x
target riscv64 has_a
; We can't test that these instructions are right regarding atomicity, but we can
; test if they perform their operation correctly

View File

@@ -0,0 +1,21 @@
test interpret
test run
target aarch64
target s390x
target x86_64
target riscv64
function %a(i8) -> i8 sext system_v {
ss2 = explicit_slot 2
block0(v0: i8):
v2 = iconst.i16 0x00ff
v3 = stack_addr.i64 ss2
store little v2, v3
v4 = stack_addr.i64 ss2+1
v5 = atomic_cas little v4, v0, v0
return v5
}
; run: %a(0) == 0