cfallin opened PR #2546 from fix-b1
to main
:
Previously,
select
andbrz
/brnz
instructions, when given ab1
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<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin requested abrown and bnjbvr for a review on PR #2546.
cfallin requested abrown and bnjbvr for a review on PR #2546.
cfallin updated PR #2546 from fix-b1
to main
:
Previously,
select
andbrz
/brnz
instructions, when given ab1
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<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
bnjbvr submitted PR Review.
bnjbvr submitted PR Review.
bnjbvr created PR Review Comment:
Would this read slightly better as
if is_cmp { if *size == 1 { 0x80 } else if use_imm8 { 0x83 } else { 0x81 } } else if *size == 1 { 0xf6 } else { 0xf7 }
?/me also wonders if rustc/llvm can rearrange the order of the comparisons here, so that
is_cmp
is checked only once in generated code.
bnjbvr created PR Review Comment:
nit: debug_assert_eq! (gives better debug output)
bnjbvr created PR Review Comment:
uber-nit: could be an int or boolean, but the
size
value matches the type size in this case.We could in fact use a
test
instruction against zero here. If so, the wholeif
can select the immediate to test against, slightly reducing code duplication here.
bnjbvr created PR Review Comment:
Pre-existing: in the above inst definition for
CmpRmiR
, can you remove/tests
from the comment? it's a bit misleading considering the new variant.
bnjbvr created PR Review Comment:
Same remark about using test in both branches here.
bnjbvr created PR Review Comment:
In fact, do we need the new variant
TestRmiR
? I had in mind that we needed to add new instructions when no other instructions matched the following:
- regalloc constraints are the same
- instruction operands are the same
- codegen is (almost) the same
In this case, it seems that
CmpRmiR
has the same behavior for the three above, so we could add one boolean field there meaningis_test
, and have one fewer enum variant in return. We can absolutely keep the constructortest_rmi_r
though, as an higher-level helper.
bnjbvr created PR Review Comment:
Do you mind duplicating this test for
brz
please?
cfallin updated PR #2546 from fix-b1
to main
:
Previously,
select
andbrz
/brnz
instructions, when given ab1
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<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin submitted PR Review.
cfallin created PR Review Comment:
Yes, that's a better idea -- merged this in and added
CmpOpcode::{Test, Cmp}
.
cfallin submitted PR Review.
cfallin created PR Review Comment:
Yes, that is a bit clearer; updated!
cfallin submitted PR Review.
cfallin created PR Review Comment:
Done.
cfallin submitted PR Review.
cfallin created PR Review Comment:
Re: the nit -- yes, good point; it could be a wider-than-1-bit bool. I'm not sure what that would mean as an input to a select or brz/brnz, so I've just added an assert that we do not see another bool type in the else-branch.
Re: using
test
always -- yes, good point; actuallytest rN, rN
is one byte shorter thancmp rN, 0
so this is a code-size win too. (rN, rN
and notrN, 0
because this is an and-op; and 0xff...ff is much larger in emitted code than the R-R form).
cfallin submitted PR Review.
cfallin created PR Review Comment:
Done!
cfallin submitted PR Review.
cfallin created PR Review Comment:
Done!
cfallin updated PR #2546 from fix-b1
to main
:
Previously,
select
andbrz
/brnz
instructions, when given ab1
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<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
bjorn3 submitted PR Review.
bjorn3 created PR Review Comment:
Please revert this. I am pretty sure that cranelif-module doesn't disable default features and as such it would become impossible to use the old backend.
cfallin submitted PR Review.
cfallin created PR Review Comment:
Eek, this slipped in from local testing. Thanks for catching this.
cfallin updated PR #2546 from fix-b1
to main
:
Previously,
select
andbrz
/brnz
instructions, when given ab1
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<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
cfallin submitted PR Review.
cfallin created PR Review Comment:
(I think that's why I was newly seeing a warning issue; CI doesn't otherwise check for warnings with non-default options.)
cfallin merged PR #2546.
Last updated: Nov 22 2024 at 17:03 UTC