Skip to content

Commit

Permalink
Auto merge of rust-lang#96862 - oli-obk:enum_cast_mir, r=RalfJung
Browse files Browse the repository at this point in the history
Change enum->int casts to not go through MIR casts.

follow-up to rust-lang#96814

this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
  • Loading branch information
bors committed Jul 5, 2022
2 parents a71e691 + 846eecb commit 96bdb39
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,29 +635,6 @@ fn codegen_stmt<'tcx>(
let (ptr, _extra) = operand.load_scalar_pair(fx);
lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
}
} else if let ty::Adt(adt_def, _substs) = from_ty.kind() {
// enum -> discriminant value
assert!(adt_def.is_enum());
match to_ty.kind() {
ty::Uint(_) | ty::Int(_) => {}
_ => unreachable!("cast adt {} -> {}", from_ty, to_ty),
}
let to_clif_ty = fx.clif_type(to_ty).unwrap();

let discriminant = crate::discriminant::codegen_get_discriminant(
fx,
operand,
fx.layout_of(operand.layout().ty.discriminant_ty(fx.tcx)),
)
.load_scalar(fx);

let res = crate::cast::clif_intcast(
fx,
discriminant,
to_clif_ty,
to_ty.is_signed(),
);
lval.write_cvalue(fx, CValue::by_val(res, dest_layout));
} else {
let to_clif_ty = fx.clif_type(to_ty).unwrap();
let from = operand.load_scalar(fx);
Expand Down

0 comments on commit 96bdb39

Please sign in to comment.