Skip to content

Commit 502f7f9

Browse files
committed
Address PR feedback
1 parent 51e67e2 commit 502f7f9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
581581
);
582582

583583
// In principle we could insert assumes on the possible range of `discr`, but
584-
// currently in LLVM this seems to be a pessimization.
584+
// currently in LLVM this isn't worth it because the original `tag` will
585+
// have either a `range` parameter attribute or `!range` metadata,
586+
// or come from a `transmute` that already `assume`d it.
585587

586588
discr
587589
}

tests/codegen/enum/enum-two-variants-match.rs

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#![crate_type = "lib"]
55

6+
// This directly tests what we emit for these matches, rather than what happens
7+
// after optimization, so it doesn't need to worry about extra flags on the
8+
// instructions and is less susceptible to being broken on LLVM updates.
9+
610
// CHECK-LABEL: @option_match
711
#[no_mangle]
812
pub fn option_match(x: Option<i32>) -> u16 {
@@ -103,10 +107,22 @@ pub fn option_ordering_match(x: Option<Ordering>) -> char {
103107
// CHECK-LABEL: @option_nonzero_match(
104108
#[no_mangle]
105109
pub fn option_nonzero_match(x: Option<std::num::NonZero<u16>>) -> u16 {
110+
// CHECK: %[[OUT:.+]] = alloca [2 x i8]
111+
106112
// CHECK: %[[IS_NONE:.+]] = icmp eq i16 %x, 0
107113
// CHECK: %[[OPT_DISCR:.+]] = select i1 %[[IS_NONE]], i64 0, i64 1
108114
// CHECK: %[[OPT_DISCR_T:.+]] = trunc nuw i64 %[[OPT_DISCR]] to i1
109115
// CHECK: br i1 %[[OPT_DISCR_T]], label %[[BB_SOME:.+]], label %[[BB_NONE:.+]]
116+
117+
// CHECK: [[BB_SOME]]:
118+
// CHECK: store i16 987, ptr %[[OUT]]
119+
120+
// CHECK: [[BB_NONE]]:
121+
// CHECK: store i16 123, ptr %[[OUT]]
122+
123+
// CHECK: %[[RET:.+]] = load i16, ptr %[[OUT]]
124+
// CHECK: ret i16 %[[RET]]
125+
110126
match x {
111127
None => 123,
112128
Some(_) => 987,

0 commit comments

Comments
 (0)