Created
June 16, 2013 20:47
-
-
Save o11c/5793379 to your computer and use it in GitHub Desktop.
missed optimizatino
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
.file "asm.ll" | |
.text | |
.globl _Z4testR6Server | |
.align 16, 0x90 | |
.type _Z4testR6Server,@function | |
_Z4testR6Server: # @_Z4testR6Server | |
.cfi_startproc | |
# BB#0: | |
pushq %rax | |
.Ltmp1: | |
.cfi_def_cfa_offset 16 | |
xorl %esi, %esi | |
movl $8192, %edx # imm = 0x2000 | |
callq memset | |
popq %rax | |
ret | |
.Ltmp2: | |
.size _Z4testR6Server, .Ltmp2-_Z4testR6Server | |
.cfi_endproc | |
.section ".note.GNU-stack","",@progbits |
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
#include <cstring> | |
#define MAX_MAP_PER_SERVER 512 | |
struct Server | |
{ | |
char maps[MAX_MAP_PER_SERVER][16]; | |
}; | |
inline | |
void strzcpy(char *dest, const char *src, size_t n) | |
{ | |
if (n) | |
{ | |
strncpy(dest, src, n); | |
dest[n - 1] = '\0'; | |
} | |
} | |
void test(Server& srv) | |
{ | |
for (char (&it)[16] : srv.maps) | |
strzcpy(it, "", 16); | |
} |
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
; ModuleID = 'asm.cpp' | |
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-linux-gnu" | |
%struct.Server = type { [512 x [16 x i8]] } | |
; Function Attrs: nounwind uwtable | |
define void @_Z4testR6Server(%struct.Server* %srv) #0 { | |
%1 = getelementptr inbounds %struct.Server* %srv, i64 0, i32 0, i64 0 | |
%2 = getelementptr inbounds %struct.Server* %srv, i64 0, i32 0, i64 512 | |
br label %3 | |
; <label>:3 ; preds = %0, %3 | |
%__begin.01 = phi [16 x i8]* [ %1, %0 ], [ %4, %3 ] | |
%4 = getelementptr inbounds [16 x i8]* %__begin.01, i64 1 | |
%5 = icmp eq [16 x i8]* %4, %2 | |
%6 = getelementptr inbounds [16 x i8]* %__begin.01, i64 0, i64 0 | |
call void @llvm.memset.p0i8.i64(i8* %6, i8 0, i64 16, i32 1, i1 false) | |
br i1 %5, label %7, label %3 | |
; <label>:7 ; preds = %3 | |
ret void | |
} | |
; Function Attrs: nounwind | |
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) #1 | |
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #1 = { nounwind } |
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
.file "asm.cpp" | |
.text | |
.globl _Z4testR6Server | |
.align 16, 0x90 | |
.type _Z4testR6Server,@function | |
_Z4testR6Server: # @_Z4testR6Server | |
.cfi_startproc | |
# BB#0: | |
xorl %eax, %eax | |
xorps %xmm0, %xmm0 | |
.align 16, 0x90 | |
.LBB0_1: # =>This Inner Loop Header: Depth=1 | |
movups %xmm0, (%rdi,%rax) | |
addq $16, %rax | |
cmpq $8192, %rax # imm = 0x2000 | |
jne .LBB0_1 | |
# BB#2: | |
ret | |
.Ltmp0: | |
.size _Z4testR6Server, .Ltmp0-_Z4testR6Server | |
.cfi_endproc | |
.section ".note.GNU-stack","",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment