Auto merge of #96862 - oli-obk:enum_cast_mir, r=RalfJung
Change enum->int casts to not go through MIR casts. follow-up to https://github.com/rust-lang/rust/pull/96814 this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
This commit is contained in:
commit
96bdb398f9
23
src/base.rs
23
src/base.rs
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user