Feature
While working on finishing the migration of the x64 backend to ISLE, I encountered a case where guarding a rule on specific ISA features being enabled caused the rule to never fire. The problem was that the rule I added overlapped with another rule except in the ISA feature check, and the other rule took precedence. Here's an example from elsewhere in the codebase:
|
(rule 1 (lower |
|
(has_type (and |
|
(ty_32_or_64 ty) |
|
(use_bmi1)) |
|
(ctz src))) |
|
(x64_tzcnt ty src)) |
|
|
|
(rule (lower |
|
(has_type (ty_32_or_64 ty) |
|
(ctz src))) |
|
(do_ctz ty ty src)) |
The LHS of the two rules only differs in the patterns to the first argument of (has_type): both rules match (ty_32_or_64 ty) while the rule on line 1799 also matches (use_bmi1). The rule on line 1799 has been given a priority of 1 to ensure that it's checked before the rule on line 1806, but ideally we wouldn't need to give this annotation here.
My proposal is that we switch to compiling ISLE by matching rules top-down, left-to-right.
Benefit
The benefit of this change would be that we could tell statically when a rule was not reachable, and raise an error when it would never fire.
Implementation
For matching on enum values we could take the approach outlined in https://www.cs.tufts.edu/~nr/cs257/archive/luc-maranget/jun08.pdf. For handling extractors we could take inspiration from GHC's implementation of view patterns.
Alternatives
We could continue to develop heuristics to determine when rules might be unconditionally shadowed, and inform the programmer through an error or warning.
Feature
While working on finishing the migration of the x64 backend to ISLE, I encountered a case where guarding a rule on specific ISA features being enabled caused the rule to never fire. The problem was that the rule I added overlapped with another rule except in the ISA feature check, and the other rule took precedence. Here's an example from elsewhere in the codebase:
wasmtime/cranelift/codegen/src/isa/x64/lower.isle
Lines 1799 to 1809 in 0f94493
The LHS of the two rules only differs in the patterns to the first argument of
(has_type): both rules match(ty_32_or_64 ty)while the rule on line 1799 also matches(use_bmi1). The rule on line 1799 has been given a priority of1to ensure that it's checked before the rule on line 1806, but ideally we wouldn't need to give this annotation here.My proposal is that we switch to compiling ISLE by matching rules top-down, left-to-right.
Benefit
The benefit of this change would be that we could tell statically when a rule was not reachable, and raise an error when it would never fire.
Implementation
For matching on
enumvalues we could take the approach outlined in https://www.cs.tufts.edu/~nr/cs257/archive/luc-maranget/jun08.pdf. For handling extractors we could take inspiration from GHC's implementation of view patterns.Alternatives
We could continue to develop heuristics to determine when rules might be unconditionally shadowed, and inform the programmer through an error or warning.