about summary refs log tree commit diff
path: root/tests/codegen-llvm
diff options
context:
space:
mode:
authorThe Miri Cronjob Bot <miri@cron.bot>2025-08-13 05:05:41 +0000
committerThe Miri Cronjob Bot <miri@cron.bot>2025-08-13 05:05:41 +0000
commit4b5f667dc4984ca65c74f68f16d094fc5e9749f7 (patch)
tree8e9d89a9f0653b4e19f4c55fdfda10952f36992b /tests/codegen-llvm
parent5a76aa26f285a6b97091f7396b7e193aab049721 (diff)
parent4d841497da34dbe1c51071d38b5b1c440ae308b7 (diff)
downloadrust-4b5f667dc4984ca65c74f68f16d094fc5e9749f7.tar.gz
rust-4b5f667dc4984ca65c74f68f16d094fc5e9749f7.zip
Merge ref '1553adfe6884' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: 1553adfe6884a8f6c28f5a673d3e605535ee0113
Filtered ref: e5ee70aa5f36dacdc6df9490e867c45aa4e51c18

This merge was created using https://github.com/rust-lang/josh-sync.
Diffstat (limited to 'tests/codegen-llvm')
-rw-r--r--tests/codegen-llvm/bigint-helpers.rs15
-rw-r--r--tests/codegen-llvm/issues/saturating-sub-index-139759.rs19
2 files changed, 31 insertions, 3 deletions
diff --git a/tests/codegen-llvm/bigint-helpers.rs b/tests/codegen-llvm/bigint-helpers.rs
index 355cccb8150..ec70a3eabed 100644
--- a/tests/codegen-llvm/bigint-helpers.rs
+++ b/tests/codegen-llvm/bigint-helpers.rs
@@ -3,11 +3,20 @@
 #![crate_type = "lib"]
 #![feature(bigint_helper_methods)]
 
+// Note that there's also an assembly test for this, which is what checks for
+// the `ADC` (Add with Carry) instruction on x86 now that the IR we emit uses
+// the preferred instruction phrasing instead of the intrinsic.
+
 // CHECK-LABEL: @u32_carrying_add
 #[no_mangle]
 pub fn u32_carrying_add(a: u32, b: u32, c: bool) -> (u32, bool) {
-    // CHECK: @llvm.uadd.with.overflow.i32
-    // CHECK: @llvm.uadd.with.overflow.i32
-    // CHECK: or disjoint i1
+    // CHECK: %[[AB:.+]] = add i32 {{%a, %b|%b, %a}}
+    // CHECK: %[[O1:.+]] = icmp ult i32 %[[AB]], %a
+    // CHECK: %[[CEXT:.+]] = zext i1 %c to i32
+    // CHECK: %[[ABC:.+]] = add i32 %[[AB]], %[[CEXT]]
+    // CHECK: %[[O2:.+]] = icmp ult i32 %[[ABC]], %[[AB]]
+    // CHECK: %[[O:.+]] = or disjoint i1 %[[O1]], %[[O2]]
+    // CHECK: insertvalue {{.+}}, i32 %[[ABC]], 0
+    // CHECK: insertvalue {{.+}}, i1 %[[O]], 1
     u32::carrying_add(a, b, c)
 }
diff --git a/tests/codegen-llvm/issues/saturating-sub-index-139759.rs b/tests/codegen-llvm/issues/saturating-sub-index-139759.rs
new file mode 100644
index 00000000000..eac2f4d306b
--- /dev/null
+++ b/tests/codegen-llvm/issues/saturating-sub-index-139759.rs
@@ -0,0 +1,19 @@
+// Test that calculating an index with saturating subtraction from an in-bounds
+// index doesn't generate another bounds check.
+
+//@ compile-flags: -Copt-level=3
+//@ min-llvm-version: 21
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: @bounds_check_is_elided
+#[no_mangle]
+pub fn bounds_check_is_elided(s: &[i32], index: usize) -> i32 {
+    // CHECK-NOT: panic_bounds_check
+    if index < s.len() {
+        let lower_bound = index.saturating_sub(1);
+        s[lower_bound]
+    } else {
+        -1
+    }
+}