abrown opened Issue #1745:
I am trying to implement a legalization for
imul.i64x2
that must be a custom legalization function. It needs to have logic to look at the ISA-specific flags to determine what legalization to use; I know, I know, this would be fixed by the new backend, but in the meantime I would like to implement this legalization. I cannot find a good transform group to put this custom legalization in: if I put it inx86_narrow
, the legalization search stops too soon and things likei128
(innarrow
) don't get legalized. If I put it in another transform group, e.g.expand
, I have to addi64x2
to the type the group legalizes, which prevents otheri64x2
operations from being legalized (all of these are currently inx86_narrow
). What can I do?
- I could move all of the SIMD operations to
x86_expand
but when I do this I run into conflicts with other operations (e.g.ineg
)- I could duplicate the logic from the shared
narrow
imul
legalizations to my custom function- I could make transform groups smarter somehow, e.g. by registering custom functions for an instruction AND a type (not just an instruction) or by allowing custom functions to return a result indicating if they succeeded (if they do, we stop; if they don't, we continue looking in other groups)
Would appreciate some help thinking through this, @bnjbvr. CCing @iximeow and @whitequark as well since it could be remotely related to #1743.
abrown edited Issue #1745:
I am trying to implement a legalization for
imul.i64x2
that must be a custom legalization function. It needs to have logic to look at the ISA-specific flags to determine what legalization to use; I know, I know, this would be fixed by the new backend, but in the meantime I would like to implement this legalization. I cannot find a good transform group to put this custom legalization in: if I put it inx86_narrow
, the legalization search stops too soon and things likei128
(innarrow
) don't get legalized. If I put it in another transform group, e.g.expand
, I have to addi64x2
as a type the group legalizes, which prevents otheri64x2
operations from being legalized (all of these are currently inx86_narrow
). What can I do?
- I could move all of the SIMD operations to
x86_expand
but when I do this I run into conflicts with other operations (e.g.ineg
)- I could duplicate the logic from the shared
narrow
imul
legalizations to my custom function- I could make transform groups smarter somehow, e.g. by registering custom functions for an instruction AND a type (not just an instruction) or by allowing custom functions to return a result indicating if they succeeded (if they do, we stop; if they don't, we continue looking in other groups)
Would appreciate some help thinking through this, @bnjbvr. CCing @iximeow and @whitequark as well since it could be remotely related to #1743.
bnjbvr commented on Issue #1745:
I could make transform groups smarter somehow, e.g. by registering custom functions for an instruction AND a type (not just an instruction) or by allowing custom functions to return a result indicating if they succeeded (if they do, we stop; if they don't, we continue looking in other groups)
There's already something like this: one can actually "chain" legalization groups when creating them, with this exact behavior. So i'd say, feel free to add as many legalization groups that you want, as long as they have a clear usefulness.
abrown commented on Issue #1745:
Ok, I think I have a clearer idea now... perhaps the title of this issue should be "make legalization groups clearer"? I added a new
x86_narrow_avx
group in #1759 but there must be a better name for that. As I looked at how the legalization graph is currently set up for x86, I thought of several improvements:
- move the SIMD instructions into
x86_expand
--this is what those are legalizations are truly doing (they are not really "narrowing"); but, as I learned, this breaks other things, because other legalizations in x86_narrow are expected to be the default group so we might need to add another level or shift things around to make this work- put the construction of the legalization graph in one place (per ISA) so it is easier to visualize what is going on; e.g. move all of the
chain_with
calls tometa/src/isa/x86/mod.rs
. Sure, this might mean some duplication for the various ISAs but I think it would be worth it for clarity.
bjorn3 commented on Issue #1745:
The new backend framework doesn't use legalizations as much as the old backend framework.
abrown closed Issue #1745:
I am trying to implement a legalization for
imul.i64x2
that must be a custom legalization function. It needs to have logic to look at the ISA-specific flags to determine what legalization to use; I know, I know, this would be fixed by the new backend, but in the meantime I would like to implement this legalization. I cannot find a good transform group to put this custom legalization in: if I put it inx86_narrow
, the legalization search stops too soon and things likei128
(innarrow
) don't get legalized. If I put it in another transform group, e.g.expand
, I have to addi64x2
as a type the group legalizes, which prevents otheri64x2
operations from being legalized (all of these are currently inx86_narrow
). What can I do?
- I could move all of the SIMD operations to
x86_expand
but when I do this I run into conflicts with other operations (e.g.ineg
)- I could duplicate the logic from the shared
narrow
imul
legalizations to my custom function- I could make transform groups smarter somehow, e.g. by registering custom functions for an instruction AND a type (not just an instruction) or by allowing custom functions to return a result indicating if they succeeded (if they do, we stop; if they don't, we continue looking in other groups)
Would appreciate some help thinking through this, @bnjbvr. CCing @iximeow and @whitequark as well since it could be remotely related to #1743.
Last updated: Nov 22 2024 at 16:03 UTC