Skip to content

Commit

Permalink
Streamline bin_op_to_[if]cmp_predicate.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Sep 17, 2024
1 parent cd3da00 commit 52c5de0
Showing 1 changed file with 13 additions and 43 deletions.
56 changes: 13 additions & 43 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,18 @@ use crate::{
};

pub(crate) fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
match op {
BinOp::Eq => IntPredicate::IntEQ,
BinOp::Ne => IntPredicate::IntNE,
BinOp::Lt => {
if signed {
IntPredicate::IntSLT
} else {
IntPredicate::IntULT
}
}
BinOp::Le => {
if signed {
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
),
match (op, signed) {
(BinOp::Eq, _) => IntPredicate::IntEQ,
(BinOp::Ne, _) => IntPredicate::IntNE,
(BinOp::Lt, true) => IntPredicate::IntSLT,
(BinOp::Lt, false) => IntPredicate::IntULT,
(BinOp::Le, true) => IntPredicate::IntSLE,
(BinOp::Le, false) => IntPredicate::IntULE,
(BinOp::Gt, true) => IntPredicate::IntSGT,
(BinOp::Gt, false) => IntPredicate::IntUGT,
(BinOp::Ge, true) => IntPredicate::IntSGE,
(BinOp::Ge, false) => IntPredicate::IntUGE,
op => bug!("bin_op_to_icmp_predicate: expected comparison operator, found {:?}", op),
}
}

Expand All @@ -92,13 +68,7 @@ pub(crate) fn bin_op_to_fcmp_predicate(op: BinOp) -> RealPredicate {
BinOp::Le => RealPredicate::RealOLE,
BinOp::Gt => RealPredicate::RealOGT,
BinOp::Ge => RealPredicate::RealOGE,
op => {
bug!(
"comparison_op_to_fcmp_predicate: expected comparison operator, \
found {:?}",
op
);
}
op => bug!("bin_op_to_fcmp_predicate: expected comparison operator, found {:?}", op),
}
}

Expand Down

0 comments on commit 52c5de0

Please sign in to comment.