-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cranelift: bnot.b1 is illegal on x86 #1743
Comments
Subscribe to Label Actioncc @bnjbvr
This issue or pull request has been labeled: "cranelift"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
I've tried legalizing it like this but it doesn't do anything: --- a/cranelift/codegen/meta/src/shared/legalize.rs
+++ b/cranelift/codegen/meta/src/shared/legalize.rs
@@ -5,6 +5,7 @@ use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups};
use crate::shared::immediates::Immediates;
use crate::shared::types::Float::{F32, F64};
use crate::shared::types::Int::{I128, I16, I32, I64, I8};
+use crate::shared::types::Bool::B1;
use cranelift_codegen_shared::condcodes::{CondCode, IntCC};
#[allow(clippy::many_single_char_names, clippy::cognitive_complexity)]
@@ -396,6 +397,14 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
);
}
+ widen.legalize(
+ def!(a = bnot.B1(b)),
+ vec![
+ def!(x = bint.I32(b)),
+ def!(a = icmp_imm.I32(intcc_eq, x, Literal::constant(&imm.uimm32, 0)))
+ ]
+ );
+
// Widen instructions with one input operand.
for &op in &[bnot, popcnt] {
for &int_ty in &[I8, I16] { |
You can try expand instead of widen. |
Tried that, it breaks with a really strange message:
|
I think that entirely confused the legalizer codegen :D I'd expect the //# Expand bnot using xor.
let minus_one = Literal::constant(&imm.imm64, -1);
expand.legalize(
def!(a = bnot(x)),
vec![def!(y = iconst(minus_one)), def!(a = bxor(x, y))],
); I'm a little at a loss as to why this doesn't apply. That said, adding a direct encoding for diff --git a/cranelift/codegen/meta/src/isa/x86/encodings.rs b/cranelift/codegen/meta/src/isa/x86/encodings.rs
index 7863e2bd8..9f1517253 100644
--- a/cranelift/codegen/meta/src/isa/x86/encodings.rs
+++ b/cranelift/codegen/meta/src/isa/x86/encodings.rs
@@ -1454,6 +1454,7 @@ fn define_alu(
// x86 has a bitwise not instruction NOT.
e.enc_i32_i64(bnot, rec_ur.opcodes(&NOT).rrr(2));
e.enc_b32_b64(bnot, rec_ur.opcodes(&NOT).rrr(2));
+ e.enc_both(bnot.bind(B1), rec_ur.opcodes(&NOT).rrr(2));
// Also add a `b1` encodings for the logic instructions.
// TODO: Should this be done with 8-bit instructions? It would improve partial register |
Fixes bytecodealliance#1743. Co-authored-by: iximeow <git@iximeow.net>
Theory: the integer immediate forbids this legalization from applying for an incompatible |
I was just looking at this but because of other problems: |
wasmtime/cranelift/codegen/meta/src/shared/legalize.rs Lines 954 to 964 in 162fcd3
wasmtime/cranelift/codegen/meta/src/isa/x86/legalize.rs Lines 11 to 19 in 4ec16fa
so I'm actually more confused at |
Ah, I think you're right: there's chaining for the DSL legalizations (I think?) but not for the custom functions? |
Fixes bytecodealliance#1743. Co-authored-by: iximeow <git@iximeow.net>
Fixes bytecodealliance#1743. Co-authored-by: iximeow <git@iximeow.net>
Fixes bytecodealliance#1743. Co-authored-by: iximeow <git@iximeow.net>
Fixes bytecodealliance#1743. Co-authored-by: iximeow <git@iximeow.net>
Fixes bytecodealliance#1743. Co-authored-by: iximeow <git@iximeow.net>
Fixes #1743. Co-authored-by: iximeow <git@iximeow.net>
While looking into another issue I minimized the following testcase, which produces invalid IR:
It seems to me that it should work but I don't understand what's the missing legalization or selection rule is in this case. @iximeow?
The text was updated successfully, but these errors were encountered: