diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-03-12 00:38:14 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-03-12 00:56:43 -0700 |
| commit | 143f39362aa3fe30e19de5d2a29bf6535e8f975f (patch) | |
| tree | cf71b92e2b37e17e8ea62f957047a28c01a47ccc /tests/codegen/enum/enum-two-variants-match.rs | |
| parent | 6650252439d4e03368b305c42a10006e36f1545e (diff) | |
| download | rust-143f39362aa3fe30e19de5d2a29bf6535e8f975f.tar.gz rust-143f39362aa3fe30e19de5d2a29bf6535e8f975f.zip | |
Don't `alloca` just to look at a discriminant
Today we're making LLVM do a bunch of extra work for every enum you match on, even trivial stuff like `Option<bool>`. Let's not.
Diffstat (limited to 'tests/codegen/enum/enum-two-variants-match.rs')
| -rw-r--r-- | tests/codegen/enum/enum-two-variants-match.rs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/tests/codegen/enum/enum-two-variants-match.rs b/tests/codegen/enum/enum-two-variants-match.rs index e5978bfc761..c1f208d7909 100644 --- a/tests/codegen/enum/enum-two-variants-match.rs +++ b/tests/codegen/enum/enum-two-variants-match.rs @@ -7,19 +7,22 @@ // CHECK-LABEL: @option_match #[no_mangle] pub fn option_match(x: Option<i32>) -> u16 { - // CHECK: %x = alloca [8 x i8] - // CHECK: store i32 %0, ptr %x - // CHECK: %[[TAG:.+]] = load i32, ptr %x - // CHECK-SAME: !range ![[ZERO_ONE_32:[0-9]+]] - // CHECK: %[[DISCR:.+]] = zext i32 %[[TAG]] to i64 + // CHECK-NOT: %x = alloca + // CHECK: %[[OUT:.+]] = alloca [2 x i8] + // CHECK-NOT: %x = alloca + + // CHECK: %[[DISCR:.+]] = zext i32 %x.0 to i64 // CHECK: %[[COND:.+]] = trunc nuw i64 %[[DISCR]] to i1 // CHECK: br i1 %[[COND]], label %[[TRUE:[a-z0-9]+]], label %[[FALSE:[a-z0-9]+]] // CHECK: [[TRUE]]: - // CHECK: store i16 13 + // CHECK: store i16 13, ptr %[[OUT]] // CHECK: [[FALSE]]: - // CHECK: store i16 42 + // CHECK: store i16 42, ptr %[[OUT]] + + // CHECK: %[[RET:.+]] = load i16, ptr %[[OUT]] + // CHECK: ret i16 %[[RET]] match x { Some(_) => 13, None => 42, @@ -29,23 +32,23 @@ pub fn option_match(x: Option<i32>) -> u16 { // CHECK-LABEL: @result_match #[no_mangle] pub fn result_match(x: Result<u64, i64>) -> u16 { - // CHECK: %x = alloca [16 x i8] - // CHECK: store i64 %0, ptr %x - // CHECK: %[[DISCR:.+]] = load i64, ptr %x - // CHECK-SAME: !range ![[ZERO_ONE_64:[0-9]+]] - // CHECK: %[[COND:.+]] = trunc nuw i64 %[[DISCR]] to i1 + // CHECK-NOT: %x = alloca + // CHECK: %[[OUT:.+]] = alloca [2 x i8] + // CHECK-NOT: %x = alloca + + // CHECK: %[[COND:.+]] = trunc nuw i64 %x.0 to i1 // CHECK: br i1 %[[COND]], label %[[TRUE:[a-z0-9]+]], label %[[FALSE:[a-z0-9]+]] // CHECK: [[TRUE]]: - // CHECK: store i16 13 + // CHECK: store i16 13, ptr %[[OUT]] // CHECK: [[FALSE]]: - // CHECK: store i16 42 + // CHECK: store i16 42, ptr %[[OUT]] + + // CHECK: %[[RET:.+]] = load i16, ptr %[[OUT]] + // CHECK: ret i16 %[[RET]] match x { Err(_) => 13, Ok(_) => 42, } } - -// CHECK: ![[ZERO_ONE_32]] = !{i32 0, i32 2} -// CHECK: ![[ZERO_ONE_64]] = !{i64 0, i64 2} |
