about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorKrishna Sai Veera Reddy <krishnasai.veerareddy@gm.com>2019-11-29 15:22:44 -0700
committerKrishna Sai Veera Reddy <krishnasai.veerareddy@gm.com>2019-11-29 15:22:44 -0700
commit4ca769ad091ef0018f5a20effaf4b4f428a034d7 (patch)
treed389a56e4d6ab7d9a93d325008259702f4095e38 /src/test/codegen
parentd99e0c6d02b159f305474f58c8c38027bb06e051 (diff)
downloadrust-4ca769ad091ef0018f5a20effaf4b4f428a034d7.tar.gz
rust-4ca769ad091ef0018f5a20effaf4b4f428a034d7.zip
Optimize Ord trait implementation for bool
Casting the booleans to `i8`s and converting their difference
into `Ordering` generates better assembly than casting them to
`u8`s and comparing them.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/bool-cmp.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/codegen/bool-cmp.rs b/src/test/codegen/bool-cmp.rs
new file mode 100644
index 00000000000..8769a4cb5e1
--- /dev/null
+++ b/src/test/codegen/bool-cmp.rs
@@ -0,0 +1,17 @@
+// This is a test for optimal Ord trait implementation for bool.
+// See <https://github.com/rust-lang/rust/issues/66780> for more info.
+
+// compile-flags: -C opt-level=3
+
+#![crate_type = "lib"]
+
+use std::cmp::Ordering;
+
+// CHECK-LABEL: @cmp_bool
+#[no_mangle]
+pub fn cmp_bool(a: bool, b: bool) -> Ordering {
+// CHECK: zext i1
+// CHECK: zext i1
+// CHECK: sub nsw
+    a.cmp(&b)
+}