Streamline bin_op_to_[if]cmp_predicate.

This commit is contained in:
Nicholas Nethercote 2024-09-11 09:55:04 +10:00
parent cd3da000c0
commit 52c5de00dc

View File

@ -45,42 +45,18 @@ use crate::{
}; };
pub(crate) fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate { pub(crate) fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
match op { match (op, signed) {
BinOp::Eq => IntPredicate::IntEQ, (BinOp::Eq, _) => IntPredicate::IntEQ,
BinOp::Ne => IntPredicate::IntNE, (BinOp::Ne, _) => IntPredicate::IntNE,
BinOp::Lt => { (BinOp::Lt, true) => IntPredicate::IntSLT,
if signed { (BinOp::Lt, false) => IntPredicate::IntULT,
IntPredicate::IntSLT (BinOp::Le, true) => IntPredicate::IntSLE,
} else { (BinOp::Le, false) => IntPredicate::IntULE,
IntPredicate::IntULT (BinOp::Gt, true) => IntPredicate::IntSGT,
} (BinOp::Gt, false) => IntPredicate::IntUGT,
} (BinOp::Ge, true) => IntPredicate::IntSGE,
BinOp::Le => { (BinOp::Ge, false) => IntPredicate::IntUGE,
if signed { op => bug!("bin_op_to_icmp_predicate: expected comparison operator, found {:?}", op),
IntPredicate::IntSLE
} else {
IntPredicate::IntULE
}
}
BinOp::Gt => {
if signed {
IntPredicate::IntSGT
} else {
IntPredicate::IntUGT
}
}
BinOp::Ge => {
if signed {
IntPredicate::IntSGE
} else {
IntPredicate::IntUGE
}
}
op => bug!(
"comparison_op_to_icmp_predicate: expected comparison operator, \
found {:?}",
op
),
} }
} }
@ -92,13 +68,7 @@ pub(crate) fn bin_op_to_fcmp_predicate(op: BinOp) -> RealPredicate {
BinOp::Le => RealPredicate::RealOLE, BinOp::Le => RealPredicate::RealOLE,
BinOp::Gt => RealPredicate::RealOGT, BinOp::Gt => RealPredicate::RealOGT,
BinOp::Ge => RealPredicate::RealOGE, BinOp::Ge => RealPredicate::RealOGE,
op => { op => bug!("bin_op_to_fcmp_predicate: expected comparison operator, found {:?}", op),
bug!(
"comparison_op_to_fcmp_predicate: expected comparison operator, \
found {:?}",
op
);
}
} }
} }