Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Last active June 18, 2018 17:21
Show Gist options
  • Save andrewrk/054ff2a6c6751f2f86ad4492f38d7cad to your computer and use it in GitHub Desktop.
Save andrewrk/054ff2a6c6751f2f86ad4492f38d7cad to your computer and use it in GitHub Desktop.
testing how much memcpy rust does
use std::env;
struct Point {
x: f32,
y: f32,
z1: u64,
z2: u64,
z3: u64,
z4: u64,
z5: u64,
}
fn main() {
let args: Vec<_> = env::args().collect();
let a = Point { x: args.len() as f32, y: 0.4,
z1: 1,
z2: 1,
z3: 1,
z4: 1,
z5: 1,
};
let b = a;
foo(b);
}
fn foo(pt: Point) {
if pt.x != 0.0 {
panic!();
}
}
; test::main
; Function Attrs: uwtable
define internal void @_ZN4test4main17h0eddcc39ebf1578fE() unnamed_addr #1 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
start:
%personalityslot = alloca { i8*, i32 }, align 8
%_10 = alloca %Point, align 8
%_8 = alloca %Point, align 8
%b = alloca %Point, align 8
%a = alloca %Point, align 8
%_2 = alloca %"std::env::Args", align 8
%args = alloca %"alloc::vec::Vec<alloc::string::String>", align 8
; call std::env::args
call void @_ZN3std3env4args17h132ed8333c374cdbE(%"std::env::Args"* noalias nocapture sret dereferenceable(32) %_2)
br label %bb2
bb1: ; preds = %bb5
%0 = bitcast { i8*, i32 }* %personalityslot to i8**
%1 = load i8*, i8** %0, align 8
%2 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %personalityslot, i32 0, i32 1
%3 = load i32, i32* %2, align 4
%4 = insertvalue { i8*, i32 } undef, i8* %1, 0
%5 = insertvalue { i8*, i32 } %4, i32 %3, 1
resume { i8*, i32 } %5
bb2: ; preds = %start
; call core::iter::iterator::Iterator::collect
call void @_ZN4core4iter8iterator8Iterator7collect17hebe2321bd3571485E(%"alloc::vec::Vec<alloc::string::String>"* noalias nocapture sret dereferenceable(24) %args, %"std::env::Args"* noalias nocapture dereferenceable(32) %_2)
br label %bb3
bb3: ; preds = %bb2
; invoke <alloc::vec::Vec<T>>::len
%6 = invoke i64 @"_ZN33_$LT$alloc..vec..Vec$LT$T$GT$$GT$3len17h2adc59324a04766cE"(%"alloc::vec::Vec<alloc::string::String>"* noalias readonly dereferenceable(24) %args)
to label %bb4 unwind label %cleanup
bb4: ; preds = %bb3
%7 = icmp ule i64 %6, -1
call void @llvm.assume(i1 %7)
%8 = uitofp i64 %6 to float
%9 = getelementptr inbounds %Point, %Point* %a, i32 0, i32 11
store float %8, float* %9, align 4
%10 = getelementptr inbounds %Point, %Point* %a, i32 0, i32 13
store float 0x3FD99999A0000000, float* %10, align 4
%11 = bitcast %Point* %a to i64*
store i64 1, i64* %11, align 8
%12 = getelementptr inbounds %Point, %Point* %a, i32 0, i32 3
store i64 1, i64* %12, align 8
%13 = getelementptr inbounds %Point, %Point* %a, i32 0, i32 5
store i64 1, i64* %13, align 8
%14 = getelementptr inbounds %Point, %Point* %a, i32 0, i32 7
store i64 1, i64* %14, align 8
%15 = getelementptr inbounds %Point, %Point* %a, i32 0, i32 9
store i64 1, i64* %15, align 8
%16 = bitcast %Point* %a to i8*
%17 = bitcast %Point* %_8 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %17, i8* %16, i64 48, i32 8, i1 false)
%18 = bitcast %Point* %_8 to i8*
%19 = bitcast %Point* %b to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %19, i8* %18, i64 48, i32 8, i1 false)
%20 = bitcast %Point* %b to i8*
%21 = bitcast %Point* %_10 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %21, i8* %20, i64 48, i32 8, i1 false)
; invoke test::foo
invoke void @_ZN4test3foo17h69fd17801fc24f3aE(%Point* noalias nocapture dereferenceable(48) %_10)
to label %bb6 unwind label %cleanup
bb5: ; preds = %cleanup
; call core::ptr::drop_in_place
call void @_ZN4core3ptr13drop_in_place17haa18e8d8db13aa5fE(%"alloc::vec::Vec<alloc::string::String>"* %args) #11
br label %bb1
bb6: ; preds = %bb4
; call core::ptr::drop_in_place
call void @_ZN4core3ptr13drop_in_place17haa18e8d8db13aa5fE(%"alloc::vec::Vec<alloc::string::String>"* %args)
br label %bb7
bb7: ; preds = %bb6
ret void
cleanup: ; preds = %bb4, %bb3
%22 = landingpad { i8*, i32 }
cleanup
%23 = extractvalue { i8*, i32 } %22, 0
%24 = extractvalue { i8*, i32 } %22, 1
%25 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %personalityslot, i32 0, i32 0
store i8* %23, i8** %25, align 8
%26 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %personalityslot, i32 0, i32 1
store i32 %24, i32* %26, align 8
br label %bb5
}
const Point = struct {
x: f32,
y: f32,
z1: u64,
z2: u64,
z3: u64,
z4: u64,
z5: u64,
};
export fn entry() void {
var arg_len: usize = 1; // zig isn't smart enough yet to make a var comptime known
const a = Point{
.x = @intToFloat(f32, arg_len),
.y = 0.4,
.z1 = 1,
.z2 = 1,
.z3 = 1,
.z4 = 1,
.z5 = 1,
};
const b = a;
foo(b);
}
fn foo(pt: Point) void {
if (pt.x != 0.0) {
@panic("aoue");
}
}
const builtin = @import("builtin");
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
while (true) {}
}
define void @entry() #2 !dbg !41 {
Entry:
%0 = alloca %Point, align 4
%arg_len = alloca i64, align 8
%a = alloca %Point, align 4
%b = alloca %Point, align 4
store i64 1, i64* %arg_len, align 8, !dbg !62
call void @llvm.dbg.declare(metadata i64* %arg_len, metadata !45, metadata !DIExpression()), !dbg !62
%1 = load i64, i64* %arg_len, align 8, !dbg !63
%2 = uitofp i64 %1 to float, !dbg !64
%3 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 0, !dbg !65
store float %2, float* %3, align 4, !dbg !65
%4 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 1, !dbg !65
store float 0x3FD99999A0000000, float* %4, align 4, !dbg !65
%5 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 2, !dbg !65
store i64 1, i64* %5, align 8, !dbg !65
%6 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 3, !dbg !65
store i64 1, i64* %6, align 8, !dbg !65
%7 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 4, !dbg !65
store i64 1, i64* %7, align 8, !dbg !65
%8 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 5, !dbg !65
store i64 1, i64* %8, align 8, !dbg !65
%9 = getelementptr inbounds %Point, %Point* %0, i32 0, i32 6, !dbg !65
store i64 1, i64* %9, align 8, !dbg !65
%10 = bitcast %Point* %0 to i8*, !dbg !66
%11 = bitcast %Point* %a to i8*, !dbg !66
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %11, i8* %10, i64 48, i32 4, i1 false), !dbg !66
call void @llvm.dbg.declare(metadata %Point* %a, metadata !47, metadata !DIExpression()), !dbg !66
%12 = bitcast %Point* %a to i8*, !dbg !67
%13 = bitcast %Point* %b to i8*, !dbg !67
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %13, i8* %12, i64 48, i32 4, i1 false), !dbg !67
call void @llvm.dbg.declare(metadata %Point* %b, metadata !60, metadata !DIExpression()), !dbg !67
call fastcc void @foo(%Point* %b), !dbg !68
ret void, !dbg !70
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment