Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 10 additions & 43 deletions cranelift/codegen/src/opts/extends.isle
Original file line number Diff line number Diff line change
Expand Up @@ -75,50 +75,17 @@
(rule (simplify (bxor bigty (uextend _ x@(value_type smallty)) (uextend _ y@(value_type smallty))))
(uextend bigty (bxor smallty x y)))

;; Matches values where `ireducing` them will not actually introduce another
;; instruction, since other rules will collapse them with the reduction.
(decl pure multi will_simplify_with_ireduce_rec (u8 Value) Value)
(rule (will_simplify_with_ireduce_rec _ x@(uextend _ _)) x)
(rule (will_simplify_with_ireduce_rec _ x@(sextend _ _)) x)
(rule (will_simplify_with_ireduce_rec _ x@(iconst _ _)) x)
(rule (will_simplify_with_ireduce_rec depth x@(unary_op _ _ a))
(if-let _ (u8_lt 0 depth))
(if-let _ (reducible_modular_op x))
(if-let _ (will_simplify_with_ireduce_rec (u8_sub depth 1) a))
x)
(rule (will_simplify_with_ireduce_rec depth x@(binary_op _ _ a b))
(if-let _ (u8_lt 0 depth))
(if-let _ (reducible_modular_op x))
(if-let _ (will_simplify_with_ireduce_rec (u8_sub depth 1) a))
(if-let _ (will_simplify_with_ireduce_rec (u8_sub depth 1) b))
x)

(decl pure multi will_simplify_with_ireduce (Value) Value)
(rule (will_simplify_with_ireduce x)
(will_simplify_with_ireduce_rec 2 x))

;; Replace `(small)(x OP y)` with `(small)x OP (small)y` in cases where that's
;; legal.
;; Matches values where the high bits of the input don't affect lower bits of
;; the output, and thus the inputs can be reduced before the operation rather
;; than doing the wide operation then reducing afterwards.
(decl pure multi reducible_modular_op (Value) Value)
(rule (reducible_modular_op x@(ineg _ _)) x)
(rule (reducible_modular_op x@(bnot _ _)) x)
(rule (reducible_modular_op x@(iadd _ _ _)) x)
(rule (reducible_modular_op x@(isub _ _ _)) x)
(rule (reducible_modular_op x@(imul _ _ _)) x)
(rule (reducible_modular_op x@(bor _ _ _)) x)
(rule (reducible_modular_op x@(bxor _ _ _)) x)
(rule (reducible_modular_op x@(band _ _ _)) x)
(rule (simplify (ireduce ty (ineg _ x))) (ineg ty (ireduce ty x)))
(rule (simplify (ireduce ty (bnot _ x))) (bnot ty (ireduce ty x)))

;; Replace `(small)(x OP y)` with `(small)x OP (small)y` in cases where that's
;; legal and it reduces the total number of instructions since the reductions
;; to the arguments simplify further.
(rule (simplify (ireduce smallty val@(unary_op _ op x)))
(if-let _ (reducible_modular_op val))
(if-let _ (will_simplify_with_ireduce x))
(unary_op smallty op (ireduce smallty x)))
(rule (simplify (ireduce smallty val@(binary_op _ op x y)))
(if-let _ (reducible_modular_op val))
(if-let _ (will_simplify_with_ireduce x))
(if-let _ (will_simplify_with_ireduce y))
(binary_op smallty op (ireduce smallty x) (ireduce smallty y)))
(rule (simplify (ireduce ty (iadd _ x y))) (iadd ty (ireduce ty x) (ireduce ty y)))
(rule (simplify (ireduce ty (isub _ x y))) (isub ty (ireduce ty x) (ireduce ty y)))
(rule (simplify (ireduce ty (imul _ x y))) (imul ty (ireduce ty x) (ireduce ty y)))
(rule (simplify (ireduce ty (bor _ x y))) (bor ty (ireduce ty x) (ireduce ty y)))
(rule (simplify (ireduce ty (bxor _ x y))) (bxor ty (ireduce ty x) (ireduce ty y)))
(rule (simplify (ireduce ty (band _ x y))) (band ty (ireduce ty x) (ireduce ty y)))
12 changes: 0 additions & 12 deletions cranelift/codegen/src/prelude_opt.isle
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,3 @@
(extractor (sextend_maybe ty val) (sextend_maybe_etor ty val))
(rule 0 (sextend_maybe ty val) (sextend ty val))
(rule 1 (sextend_maybe ty val@(value_type ty)) val)

(decl unary_op (Type Opcode Value) Value)
(extractor (unary_op ty opcode x)
(inst_data ty (InstructionData.Unary opcode x)))
(rule (unary_op ty opcode x)
(make_inst ty (InstructionData.Unary opcode x)))

(decl binary_op (Type Opcode Value Value) Value)
(extractor (binary_op ty opcode x y)
(inst_data ty (InstructionData.Binary opcode (value_array_2 x y))))
(rule (binary_op ty opcode x y)
(make_inst ty (InstructionData.Binary opcode (value_array_2_ctor x y))))