about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-10-30 17:45:04 +0000
committerbors <bors@rust-lang.org>2022-10-30 17:45:04 +0000
commitf42b6fa7cad0d221b0c5407dca70b085784b1b5e (patch)
treee59b94ba87f1853f5cea069b3d39ba0551dc55f4 /src/test/codegen
parent5ab74459b86465e751fc8f6fa9934687423ce2a6 (diff)
parent783301298f1e151b82c1be21bc6a214b9ef525bd (diff)
Auto merge of #103299 - nikic:usub-overflow, r=wesleywiser
Don't use usub.with.overflow intrinsic

The canonical form of a usub.with.overflow check in LLVM are separate sub + icmp instructions, rather than a usub.with.overflow intrinsic. Using usub.with.overflow will generally result in worse optimization potential.

The backend will attempt to form usub.with.overflow when it comes to actual instruction selection. This is not fully reliable, but I believe this is a better tradeoff than using the intrinsic in IR.

Fixes #103285.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/issue-103285-ptr-addr-overflow-check.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/codegen/issue-103285-ptr-addr-overflow-check.rs b/src/test/codegen/issue-103285-ptr-addr-overflow-check.rs
new file mode 100644
index 00000000000..a3499babea2
--- /dev/null
+++ b/src/test/codegen/issue-103285-ptr-addr-overflow-check.rs
@@ -0,0 +1,16 @@
+// compile-flags: -O -C debug-assertions=yes
+
+#![crate_type = "lib"]
+#![feature(strict_provenance)]
+
+#[no_mangle]
+pub fn test(src: *const u8, dst: *const u8) -> usize {
+    // CHECK-LABEL: @test(
+    // CHECK-NOT: panic
+    let src_usize = src.addr();
+    let dst_usize = dst.addr();
+    if src_usize > dst_usize {
+        return src_usize - dst_usize;
+    }
+    return 0;
+}