x64: handle tests of b1 values correctly (only LSB is defined).
Previously, `select` and `brz`/`brnz` instructions, when given a `b1` boolean argument, would test whether that boolean argument was nonzero, rather than whether its LSB was nonzero. Since our invariant for mapping CLIF state to machine state is that bits beyond the width of a value are undefined, the proper lowering is to test only the LSB. (aarch64 does not have the same issue because its `Extend` pseudoinst already properly handles masking of b1 values when a zero-extend is requested, as it is for select/brz/brnz.) Found by Nathan Ringo on Zulip [1] (thanks!). [1] https://bytecodealliance.zulipchat.com/#narrow/stream/217117-cranelift/topic/bnot.20on.20b1s
This commit is contained in:
@@ -2648,6 +2648,88 @@ fn test_x64_emit() {
|
||||
"cmpb %r13b, %r14b",
|
||||
));
|
||||
|
||||
// ========================================================
|
||||
// TestRmiR
|
||||
insns.push((
|
||||
Inst::test_rmi_r(8, RegMemImm::reg(r15), rdx),
|
||||
"4C85FA",
|
||||
"testq %r15, %rdx",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(8, RegMemImm::mem(Amode::imm_reg(99, rdi)), rdx),
|
||||
"48855763",
|
||||
"testq 99(%rdi), %rdx",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(8, RegMemImm::imm(76543210), rdx),
|
||||
"48F7C2EAF48F04",
|
||||
"testq $76543210, %rdx",
|
||||
));
|
||||
//
|
||||
insns.push((
|
||||
Inst::test_rmi_r(4, RegMemImm::reg(r15), rdx),
|
||||
"4485FA",
|
||||
"testl %r15d, %edx",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(4, RegMemImm::mem(Amode::imm_reg(99, rdi)), rdx),
|
||||
"855763",
|
||||
"testl 99(%rdi), %edx",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(4, RegMemImm::imm(76543210), rdx),
|
||||
"F7C2EAF48F04",
|
||||
"testl $76543210, %edx",
|
||||
));
|
||||
//
|
||||
insns.push((
|
||||
Inst::test_rmi_r(2, RegMemImm::reg(r15), rdx),
|
||||
"664485FA",
|
||||
"testw %r15w, %dx",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(2, RegMemImm::mem(Amode::imm_reg(99, rdi)), rdx),
|
||||
"66855763",
|
||||
"testw 99(%rdi), %dx",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(2, RegMemImm::imm(23210), rdx),
|
||||
"66F7C2AA5A",
|
||||
"testw $23210, %dx",
|
||||
));
|
||||
//
|
||||
insns.push((
|
||||
Inst::test_rmi_r(1, RegMemImm::reg(r15), rdx),
|
||||
"4484FA",
|
||||
"testb %r15b, %dl",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(1, RegMemImm::mem(Amode::imm_reg(99, rdi)), rdx),
|
||||
"845763",
|
||||
"testb 99(%rdi), %dl",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(1, RegMemImm::imm(70), rdx),
|
||||
"F6C246",
|
||||
"testb $70, %dl",
|
||||
));
|
||||
// Extra byte-cases (paranoia!) for test_rmi_r for first operand = R
|
||||
insns.push((
|
||||
Inst::test_rmi_r(1, RegMemImm::reg(rax), rbx),
|
||||
"84C3",
|
||||
"testb %al, %bl",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(1, RegMemImm::reg(rcx), rsi),
|
||||
"4084CE",
|
||||
"testb %cl, %sil",
|
||||
));
|
||||
insns.push((
|
||||
Inst::test_rmi_r(1, RegMemImm::reg(rcx), r10),
|
||||
"4184CA",
|
||||
"testb %cl, %r10b",
|
||||
));
|
||||
|
||||
// ========================================================
|
||||
// SetCC
|
||||
insns.push((Inst::setcc(CC::O, w_rsi), "400F90C6", "seto %sil"));
|
||||
|
||||
Reference in New Issue
Block a user