Auto merge of #91279 - scottmcm:small-refactor, r=nagisa
Small mir-opt refactor Hopefully-non-controversial changes from some not-ready-yet work that I'd figured I'd submit on their own.
This commit is contained in:
commit
0fb1c371d4
4 changed files with 11 additions and 23 deletions
|
@ -83,20 +83,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstGotoOptimizationFinder<'a, 'tcx> {
|
|||
// Now find which value in the Switch matches the const value.
|
||||
let const_value =
|
||||
_const.literal.try_eval_bits(self.tcx, self.param_env, switch_ty)?;
|
||||
let found_value_idx_option = targets
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, (value, _))| const_value == *value)
|
||||
.map(|(idx, _)| idx);
|
||||
|
||||
let target_to_use_in_goto =
|
||||
if let Some(found_value_idx) = found_value_idx_option {
|
||||
targets.iter().nth(found_value_idx).unwrap().1
|
||||
} else {
|
||||
// If we did not find the const value in values, it must be the otherwise case
|
||||
targets.otherwise()
|
||||
};
|
||||
|
||||
let target_to_use_in_goto = targets.target_for_value(const_value);
|
||||
self.optimizations.push(OptimizationToApply {
|
||||
bb_with_goto: location.block,
|
||||
target_to_use_in_goto,
|
||||
|
|
|
@ -33,15 +33,8 @@ impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
|
|||
} => {
|
||||
let constant = c.literal.try_eval_bits(tcx, param_env, switch_ty);
|
||||
if let Some(constant) = constant {
|
||||
let otherwise = targets.otherwise();
|
||||
let mut ret = TerminatorKind::Goto { target: otherwise };
|
||||
for (v, t) in targets.iter() {
|
||||
if v == constant {
|
||||
ret = TerminatorKind::Goto { target: t };
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret
|
||||
let target = targets.target_for_value(constant);
|
||||
TerminatorKind::Goto { target }
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue