From d6c73ebbf3df1331eb60a6fba1f4b0bd03274f49 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 | 15 +++++++++++++++ 1 file changed, 15 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..f2b331c315dce --- /dev/null +++ b/tests/codegen/const-array.rs @@ -0,0 +1,15 @@ +//@ 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 } +}