-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let codegen decide when to
mem::swap
with immediates
Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. So introduce a new `typed_swap` intrinsic with a fallback body, but replace that implementation for immediates and scalar pairs.
- Loading branch information
Showing
10 changed files
with
191 additions
and
27 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,50 @@ | ||
//@ only-x86_64 | ||
//@ assembly-output: emit-asm | ||
//@ compile-flags: --crate-type=lib -O | ||
|
||
use std::arch::x86_64::__m128; | ||
use std::mem::swap; | ||
|
||
// CHECK-LABEL: swap_i32: | ||
#[no_mangle] | ||
pub fn swap_i32(x: &mut i32, y: &mut i32) { | ||
// CHECK: movl (%[[ARG1:.+]]), %[[T1:.+]] | ||
// CHECK: movl (%[[ARG2:.+]]), %[[T2:.+]] | ||
// CHECK: movl %[[T2]], (%[[ARG1]]) | ||
// CHECK: movl %[[T1]], (%[[ARG2]]) | ||
// CHECK: retq | ||
swap(x, y) | ||
} | ||
|
||
// CHECK-LABEL: swap_pair: | ||
#[no_mangle] | ||
pub fn swap_pair(x: &mut (i32, u32), y: &mut (i32, u32)) { | ||
// CHECK: movq (%[[ARG1]]), %[[T1:.+]] | ||
// CHECK: movq (%[[ARG2]]), %[[T2:.+]] | ||
// CHECK: movq %[[T2]], (%[[ARG1]]) | ||
// CHECK: movq %[[T1]], (%[[ARG2]]) | ||
// CHECK: retq | ||
swap(x, y) | ||
} | ||
|
||
// CHECK-LABEL: swap_str: | ||
#[no_mangle] | ||
pub fn swap_str<'a>(x: &mut &'a str, y: &mut &'a str) { | ||
// CHECK: movups (%[[ARG1]]), %[[T1:xmm.]] | ||
// CHECK: movups (%[[ARG2]]), %[[T2:xmm.]] | ||
// CHECK: movups %[[T2]], (%[[ARG1]]) | ||
// CHECK: movups %[[T1]], (%[[ARG2]]) | ||
// CHECK: retq | ||
swap(x, y) | ||
} | ||
|
||
// CHECK-LABEL: swap_simd: | ||
#[no_mangle] | ||
pub fn swap_simd(x: &mut __m128, y: &mut __m128) { | ||
// CHECK: movaps (%[[ARG1]]), %[[T1:xmm.]] | ||
// CHECK: movaps (%[[ARG2]]), %[[T2:xmm.]] | ||
// CHECK: movaps %[[T2]], (%[[ARG1]]) | ||
// CHECK: movaps %[[T1]], (%[[ARG2]]) | ||
// CHECK: retq | ||
swap(x, y) | ||
} |
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,58 @@ | ||
//@ compile-flags: -O -C no-prepopulate-passes | ||
//@ only-64bit (so I don't need to worry about usize) | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::mem::swap; | ||
|
||
// CHECK-LABEL: @swap_unit( | ||
#[no_mangle] | ||
pub fn swap_unit(x: &mut (), y: &mut ()) { | ||
// CHECK: start | ||
// CHECK-NEXT: ret void | ||
swap(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @swap_i32( | ||
#[no_mangle] | ||
pub fn swap_i32(x: &mut i32, y: &mut i32) { | ||
// CHECK-NOT: alloca | ||
|
||
// CHECK: %[[TEMP:.+]] = load i32, ptr %x, align 4 | ||
// CHECK-SAME: !noundef | ||
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 4, i1 false) | ||
// CHECK: store i32 %0, ptr %y, align 4 | ||
// CHECK: ret void | ||
swap(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @swap_pair( | ||
#[no_mangle] | ||
pub fn swap_pair(x: &mut (i32, u32), y: &mut (i32, u32)) { | ||
// CHECK-NOT: alloca | ||
|
||
// CHECK: load i32 | ||
// CHECK-SAME: !noundef | ||
// CHECK: load i32 | ||
// CHECK-SAME: !noundef | ||
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 8, i1 false) | ||
// CHECK: store i32 | ||
// CHECK: store i32 | ||
swap(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @swap_str( | ||
#[no_mangle] | ||
pub fn swap_str<'a>(x: &mut &'a str, y: &mut &'a str) { | ||
// CHECK-NOT: alloca | ||
|
||
// CHECK: load ptr | ||
// CHECK-SAME: !nonnull | ||
// CHECK-SAME: !noundef | ||
// CHECK: load i64 | ||
// CHECK-SAME: !noundef | ||
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x, ptr align 8 %y, i64 16, i1 false) | ||
// CHECK: store ptr | ||
// CHECK: store i64 | ||
swap(x, y) | ||
} |
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