Skip to content

Commit

Permalink
Auto merge of rust-lang#94570 - shampoofactory:reopen-91719, r=workin…
Browse files Browse the repository at this point in the history
…gjubilee

Reopen 91719

Reopened rust-lang#91719, which was closed inadvertently due to technical difficulties.
  • Loading branch information
bors committed Mar 4, 2022
2 parents 047f9c4 + 0c13186 commit b4bf56c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 54 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3226,12 +3226,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
_ => return,
}

// Pass and return structures up to 2 pointers in size by value, matching `ScalarPair`.
// LLVM will usually pass these in 2 registers, which is more efficient than by-ref.
let max_by_val_size = Pointer.size(self) * 2;
let size = arg.layout.size;

if arg.layout.is_unsized() || size > max_by_val_size {
if arg.layout.is_unsized() || size > Pointer.size(self) {
arg.make_indirect();
} else {
// We want to pass small aggregates as immediates, but using
Expand Down
32 changes: 0 additions & 32 deletions src/test/codegen/arg-return-value-in-reg.rs

This file was deleted.

40 changes: 31 additions & 9 deletions src/test/codegen/array-equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

// CHECK-LABEL: @array_eq_value
#[no_mangle]
pub fn array_eq_value(a: [u16; 6], b: [u16; 6]) -> bool {
pub fn array_eq_value(a: [u16; 3], b: [u16; 3]) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: %2 = icmp eq i96 %0, %1
// CHECK-NEXT: %2 = icmp eq i48 %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 {
pub fn array_eq_ref(a: &[u16; 3], b: &[u16; 3]) -> bool {
// CHECK: start:
// CHECK: load i96, i96* %{{.+}}, align 2
// CHECK: load i96, i96* %{{.+}}, align 2
// CHECK: icmp eq i96
// CHECK: load i48, i48* %{{.+}}, align 2
// CHECK: load i48, i48* %{{.+}}, align 2
// CHECK: icmp eq i48
// CHECK-NEXT: ret
a == b
}
Expand Down Expand Up @@ -47,11 +47,33 @@ pub fn array_eq_long(a: &[u16; 1234], b: &[u16; 1234]) -> bool {
a == b
}

// CHECK-LABEL: @array_eq_zero(i128 %0)
// CHECK-LABEL: @array_eq_zero_short(i48
#[no_mangle]
pub fn array_eq_zero(x: [u16; 8]) -> bool {
pub fn array_eq_zero_short(x: [u16; 3]) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i128 %0, 0
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i48 %0, 0
// CHECK-NEXT: ret i1 %[[EQ]]
x == [0; 3]
}

// CHECK-LABEL: @array_eq_zero_mid([8 x i16]*
#[no_mangle]
pub fn array_eq_zero_mid(x: [u16; 8]) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: bitcast
// CHECK-NEXT: %[[LOAD:.+]] = load i128,
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i128 %[[LOAD]], 0
// CHECK-NEXT: ret i1 %[[EQ]]
x == [0; 8]
}

// CHECK-LABEL: @array_eq_zero_long([1234 x i16]*
#[no_mangle]
pub fn array_eq_zero_long(x: [u16; 1234]) -> bool {
// CHECK-NEXT: start:
// CHECK-NOT: alloca
// CHECK: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
// CHECK-NEXT: ret i1 %[[EQ]]
x == [0; 1234]
}
32 changes: 32 additions & 0 deletions src/test/codegen/autovectorize-f32x4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// compile-flags: -C opt-level=3
// only-x86_64
#![crate_type = "lib"]

// CHECK-LABEL: @auto_vectorize_direct
#[no_mangle]
pub fn auto_vectorize_direct(a: [f32; 4], b: [f32; 4]) -> [f32; 4] {
// CHECK: load <4 x float>
// CHECK: load <4 x float>
// CHECK: fadd <4 x float>
// CHECK: store <4 x float>
[
a[0] + b[0],
a[1] + b[1],
a[2] + b[2],
a[3] + b[3],
]
}

// CHECK-LABEL: @auto_vectorize_loop
#[no_mangle]
pub fn auto_vectorize_loop(a: [f32; 4], b: [f32; 4]) -> [f32; 4] {
// CHECK: load <4 x float>
// CHECK: load <4 x float>
// CHECK: fadd <4 x float>
// CHECK: store <4 x float>
let mut c = [0.0; 4];
for i in 0..4 {
c[i] = a[i] + b[i];
}
c
}
11 changes: 3 additions & 8 deletions src/test/codegen/union-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,11 @@ pub union UnionU128{a:u128}
#[no_mangle]
pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }

pub union UnionU128x2{a:(u128, u128)}
// CHECK: define void @test_UnionU128x2(i128 %_1.0, i128 %_1.1)
#[no_mangle]
pub fn test_UnionU128x2(_: UnionU128x2) { loop {} }

#[repr(C)]
pub union CUnionU128x2{a:(u128, u128)}
// CHECK: define void @test_CUnionU128x2(%CUnionU128x2* {{.*}} %_1)
pub union CUnionU128{a:u128}
// CHECK: define void @test_CUnionU128(%CUnionU128* {{.*}} %_1)
#[no_mangle]
pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
pub fn test_CUnionU128(_: CUnionU128) { loop {} }

pub union UnionBool { b:bool }
// CHECK: define noundef zeroext i1 @test_UnionBool(i8 %b)
Expand Down

0 comments on commit b4bf56c

Please sign in to comment.