diff --git a/cranelift/codegen/src/isa/x64/inst.isle b/cranelift/codegen/src/isa/x64/inst.isle index 2392166c77e9..22973606b3f3 100644 --- a/cranelift/codegen/src/isa/x64/inst.isle +++ b/cranelift/codegen/src/isa/x64/inst.isle @@ -3181,6 +3181,9 @@ (let ((size OperandSize (raw_operand_size_of_type ty))) (icmp_cond_result (x64_cmp size b a) cc))) +;; 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) (let ((size OperandSize (raw_operand_size_of_type ty))) (icmp_cond_result (x64_cmp size a b) (intcc_reverse cc))))