From 95aca052b5e6e9fde8b85188e6fe761c848afd75 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 28 Dec 2024 10:14:46 -0500 Subject: [PATCH] Added a codegen test for optimization with const arrays Closes #107208 --- tests/codegen/const-array.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/codegen/const-array.rs diff --git a/tests/codegen/const-array.rs b/tests/codegen/const-array.rs new file mode 100644 index 0000000000000..f23079627351c --- /dev/null +++ b/tests/codegen/const-array.rs @@ -0,0 +1,22 @@ +//@ compile-flags: -O + +#![crate_type = "lib"] + +const LUT: [u8; 2] = [ + 1, + 1, +]; + +// CHECK-LABEL: @decode +#[no_mangle] +pub fn decode(i: u8) -> u8 { + // CHECK: start: + // CHECK-NEXT: icmp + // CHECK-NEXT: select + // CHECK-NEXT: ret + if i < 2 { + LUT[i as usize] + } else { + 2 + } +}