x64: Remove unnecessary register use when comparing against constants#4645
Conversation
| ;; As a special case, reverse the arguments to the comparison when the LHS is a | ||
| ;; constant. This ensures that we avoid moving the constant into a register when | ||
| ;; performing the comparison. | ||
| (rule 1 (emit_cmp cc (and (simm32_from_value a) (value_type ty)) b) |
There was a problem hiding this comment.
I'm not super happy with the need for a rule priority here, and would have expected the simm32_from_value use to render it unnecessary. Any idea why it doesn't fire without higher priority?
Subscribe to Label ActionDetailsThis issue or pull request has been labeled: "cranelift", "cranelift:area:x64", "isle"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
cfallin
left a comment
There was a problem hiding this comment.
This looks good to me as-is, but I'm curious to see if the rule-priority tweak we talked about today removes the need for the priority here before we merge it...
The bugfix you linked removes the need for the explicit priority here, so I'll make a separate PR for that before merging this without the priority 👍 |
bb4bbfb to
8bb3209
Compare
8bb3209 to
8f6762b
Compare
8f6762b to
dfc12a0
Compare
When lowering instructions like
icmp eq (iconst 0), v2, we currently store the constant0in a register before performing the comparison. The result is that for inputs like the following:we generate this assembly:
This PR introduces a case into
emit_cmpthat handles constants on the left-hand side of a comparison by swapping the order and reversing the operation. With this new rule, we emit the following assembly for the clif snippet above: