Skip to content

Commit 96bdb39

Browse files
committed
Auto merge of rust-lang#96862 - oli-obk:enum_cast_mir, r=RalfJung
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.
2 parents a71e691 + 846eecb commit 96bdb39

File tree

1 file changed

+0
-23
lines changed

1 file changed

+0
-23
lines changed

src/base.rs

-23
Original file line numberDiff line numberDiff line change
@@ -635,29 +635,6 @@ fn codegen_stmt<'tcx>(
635635
let (ptr, _extra) = operand.load_scalar_pair(fx);
636636
lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
637637
}
638-
} else if let ty::Adt(adt_def, _substs) = from_ty.kind() {
639-
// enum -> discriminant value
640-
assert!(adt_def.is_enum());
641-
match to_ty.kind() {
642-
ty::Uint(_) | ty::Int(_) => {}
643-
_ => unreachable!("cast adt {} -> {}", from_ty, to_ty),
644-
}
645-
let to_clif_ty = fx.clif_type(to_ty).unwrap();
646-
647-
let discriminant = crate::discriminant::codegen_get_discriminant(
648-
fx,
649-
operand,
650-
fx.layout_of(operand.layout().ty.discriminant_ty(fx.tcx)),
651-
)
652-
.load_scalar(fx);
653-
654-
let res = crate::cast::clif_intcast(
655-
fx,
656-
discriminant,
657-
to_clif_ty,
658-
to_ty.is_signed(),
659-
);
660-
lval.write_cvalue(fx, CValue::by_val(res, dest_layout));
661638
} else {
662639
let to_clif_ty = fx.clif_type(to_ty).unwrap();
663640
let from = operand.load_scalar(fx);

0 commit comments

Comments
 (0)