about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2024-12-29 10:00:19 +1100
committerGitHub <noreply@github.com>2024-12-29 10:00:19 +1100
commit0a52407d4301e0bd38685058c24f51e287dce22c (patch)
treee3e13aebf1f9b1ecc380b74f42bc20e71d735541
parent8060f58150618287955228c2cb8c3b53f12e722f (diff)
parentd6c73ebbf3df1331eb60a6fba1f4b0bd03274f49 (diff)
downloadrust-0a52407d4301e0bd38685058c24f51e287dce22c.tar.gz
rust-0a52407d4301e0bd38685058c24f51e287dce22c.zip
Rollup merge of #134852 - alex:patch-1, r=durin42
Added a codegen test for optimization with const arrays

Closes #107208
-rw-r--r--tests/codegen/const-array.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/codegen/const-array.rs b/tests/codegen/const-array.rs
new file mode 100644
index 00000000000..f2b331c315d
--- /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 }
+}