about summary refs log tree commit diff
path: root/tests/codegen/const-array.rs
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2024-12-28 10:14:46 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2024-12-28 13:28:35 -0600
commitd6c73ebbf3df1331eb60a6fba1f4b0bd03274f49 (patch)
tree2614d9d3dbde5c7988204ba9a2b34bdeb9f4cdb2 /tests/codegen/const-array.rs
parentceb0441e82259c6fca91aa5aea391e9d0f3ec272 (diff)
downloadrust-d6c73ebbf3df1331eb60a6fba1f4b0bd03274f49.tar.gz
rust-d6c73ebbf3df1331eb60a6fba1f4b0bd03274f49.zip
Added a codegen test for optimization with const arrays
Closes #107208
Diffstat (limited to 'tests/codegen/const-array.rs')
-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 }
+}