remove iadd_cout and isub_bout (#6198)

This commit is contained in:
T0b1-iOS
2023-04-12 01:39:32 +02:00
committed by GitHub
parent c0166f78f9
commit f684a5fbee
16 changed files with 7 additions and 390 deletions

View File

@@ -60,7 +60,7 @@ pub fn is_pure_for_egraph(func: &Function, inst: Inst) -> bool {
};
// Multi-value results do not play nicely with much of the egraph
// infrastructure. They are in practice used only for multi-return
// calls and some other odd instructions (e.g. iadd_cout) which,
// calls and some other odd instructions (e.g. uadd_overflow) which,
// for now, we can afford to leave in place as opaque
// side-effecting ops. So if more than one result, then the inst
// is "not pure". Similarly, ops with zero results can be used

View File

@@ -1644,7 +1644,7 @@ mod tests {
assert_eq!(pos.func.dfg.resolve_aliases(v1), v1);
let arg0 = pos.func.dfg.append_block_param(block0, types::I32);
let (s, c) = pos.ins().iadd_cout(v1, arg0);
let (s, c) = pos.ins().uadd_overflow(v1, arg0);
let iadd = match pos.func.dfg.value_def(s) {
ValueDef::Result(i, 0) => i,
_ => panic!(),
@@ -1654,7 +1654,7 @@ mod tests {
pos.func.dfg.clear_results(iadd);
pos.func.dfg.attach_result(iadd, s);
// Replace `iadd_cout` with a normal `iadd` and an `icmp`.
// Replace `uadd_overflow` with a normal `iadd` and an `icmp`.
pos.func.dfg.replace(iadd).iadd(v1, arg0);
let c2 = pos.ins().icmp(IntCC::Equal, s, v1);
pos.func.dfg.change_to_alias(c, c2);

View File

@@ -2575,43 +2575,6 @@
(lower_msb Reg (lsr_imm $I64 lower_msb (imm_shift_from_u8 63))))
(add_shift $I64 lower_msb upper_msb (lshl_from_u64 $I64 1))))
;;; Rules for `iadd_cout` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; For values smaller than a register, we do a normal `add` with both arguments
;; sign extended. We then check if the output sign bit has flipped.
(rule 0 (lower (has_type (fits_in_16 ty) (iadd_cout a b)))
(let ((extend ExtendOp (lower_extend_op ty (ArgumentExtension.Sext)))
;; Instead of emitting two `sxt{b,h}` we do one as an instruction and
;; the other as an extend operation in the `add` instruction.
;;
;; sxtb a_sext, a
;; add out, a_sext, b, sxtb
;; cmp out, out, sxtb
;; cset out_carry, ne
(a_sext Reg (put_in_reg_sext32 a))
(out Reg (add_extend_op ty a_sext b extend))
(out_carry Reg (with_flags_reg
(cmp_extend (OperandSize.Size32) out out extend)
(cset (Cond.Ne)))))
(output_pair
(value_reg out)
(value_reg out_carry))))
;; For register sized add's we just emit a adds+cset, without further masking.
;;
;; adds out, a, b
;; cset carry, vs
(rule 1 (lower (has_type (ty_32_or_64 ty) (iadd_cout a b)))
(let ((out ValueRegs
(with_flags
(add_with_flags_paired ty a b)
(cset_paired (Cond.Vs)))))
(output_pair
(value_regs_get out 0)
(value_regs_get out 1))))
;;; Rules for `uadd_overflow_trap` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(rule (lower (has_type (fits_in_64 ty) (uadd_overflow_trap a b tc)))

View File

@@ -98,19 +98,6 @@
(with_flags (x64_add_with_flags_paired $I64 x_lo y_lo)
(x64_adc_paired $I64 x_hi y_hi)))))
;;;; Rules for `iadd_cout` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TODO: i8 and i16 support. Requires either learning how to encode ALU
;; operations on values narrower than 32-bits (better code; big change) or doing
;; the same extend-to-32-bits trick that aarch64 does (worse code; small
;; change).
(rule (lower (iadd_cout x y @ (value_type (ty_32_or_64 ty))))
(let ((results ValueRegs (with_flags (x64_add_with_flags_paired ty x y)
(x64_setcc_paired (CC.O)))))
(output_pair (value_regs_get results 0)
(value_regs_get results 1))))
;;;; Helpers for `*_overflow` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(decl construct_overflow_op (CC ProducesFlags) InstOutput)

View File

@@ -129,7 +129,6 @@ fn harvest_candidate_lhs(
| ir::Opcode::Clz
| ir::Opcode::Ctz
// TODO: ir::Opcode::IaddCarry
// TODO: ir::Opcode::IaddCout
| ir::Opcode::SaddSat
| ir::Opcode::SsubSat
| ir::Opcode::UsubSat => true,
@@ -470,7 +469,6 @@ fn harvest_candidate_lhs(
ast::Instruction::Cttz { a }.into()
}
// TODO: ir::Opcode::IaddCarry
// TODO: ir::Opcode::IaddCout
(ir::Opcode::SaddSat, _) => {
let a = arg(allocs, 0);
let b = arg(allocs, 1);