forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop generating
alloca
s+memcmp
for simple array equality
- Loading branch information
Showing
12 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// compile-flags: -O | ||
// only-x86_64 | ||
|
||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: @array_eq_value | ||
#[no_mangle] | ||
pub fn array_eq_value(a: [u16; 6], b: [u16; 6]) -> bool { | ||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: %2 = icmp eq i96 %0, %1 | ||
// CHECK-NEXT: ret i1 %2 | ||
a == b | ||
} | ||
|
||
// CHECK-LABEL: @array_eq_ref | ||
#[no_mangle] | ||
pub fn array_eq_ref(a: &[u16; 6], b: &[u16; 6]) -> bool { | ||
// CHECK: start: | ||
// CHECK: load i96, i96* %{{.+}}, align 2 | ||
// CHECK: load i96, i96* %{{.+}}, align 2 | ||
// CHECK: icmp eq i96 | ||
// CHECK-NEXT: ret | ||
a == b | ||
} | ||
|
||
// CHECK-LABEL: @array_eq_long | ||
#[no_mangle] | ||
pub fn array_eq_long(a: &[u16; 1234], b: &[u16; 1234]) -> bool { | ||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: bitcast | ||
// CHECK-NEXT: bitcast | ||
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* nonnull dereferenceable(2468) %{{.+}}, i8* nonnull dereferenceable(2468) %{{.+}}, i64 2468) | ||
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0 | ||
// CHECK-NEXT: ret i1 %[[EQ]] | ||
a == b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(const_intrinsic_raw_eq)] | ||
#![deny(const_err)] | ||
|
||
const BAD_RAW_EQ_CALL: bool = unsafe { | ||
std::intrinsics::raw_eq(&(1_u8, 2_u16), &(1_u8, 2_u16)) | ||
//~^ ERROR any use of this value will cause an error | ||
//~| WARNING this was previously accepted by the compiler but is being phased out | ||
}; | ||
|
||
pub fn main() { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/intrinsic-raw_eq-const-padding.rs:6:5 | ||
| | ||
LL | / const BAD_RAW_EQ_CALL: bool = unsafe { | ||
LL | | std::intrinsics::raw_eq(&(1_u8, 2_u16), &(1_u8, 2_u16)) | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reading 4 bytes of memory starting at alloc2, but 1 byte is uninitialized starting at alloc2+0x1, and this operation requires initialized memory | ||
LL | | | ||
LL | | | ||
LL | | }; | ||
| |__- | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/intrinsic-raw_eq-const-padding.rs:3:9 | ||
| | ||
LL | #![deny(const_err)] | ||
| ^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// run-pass | ||
|
||
#![feature(core_intrinsics)] | ||
#![feature(const_intrinsic_raw_eq)] | ||
#![deny(const_err)] | ||
|
||
pub fn main() { | ||
use std::intrinsics::raw_eq; | ||
|
||
const RAW_EQ_I32_TRUE: bool = unsafe { raw_eq(&42_i32, &42) }; | ||
assert!(RAW_EQ_I32_TRUE); | ||
|
||
const RAW_EQ_I32_FALSE: bool = unsafe { raw_eq(&4_i32, &2) }; | ||
assert!(!RAW_EQ_I32_FALSE); | ||
|
||
const RAW_EQ_CHAR_TRUE: bool = unsafe { raw_eq(&'a', &'a') }; | ||
assert!(RAW_EQ_CHAR_TRUE); | ||
|
||
const RAW_EQ_CHAR_FALSE: bool = unsafe { raw_eq(&'a', &'A') }; | ||
assert!(!RAW_EQ_CHAR_FALSE); | ||
|
||
const RAW_EQ_ARRAY_TRUE: bool = unsafe { raw_eq(&[13_u8, 42], &[13, 42]) }; | ||
assert!(RAW_EQ_ARRAY_TRUE); | ||
|
||
const RAW_EQ_ARRAY_FALSE: bool = unsafe { raw_eq(&[13_u8, 42], &[42, 13]) }; | ||
assert!(!RAW_EQ_ARRAY_FALSE); | ||
} |