Skip to content

Instantly share code, notes, and snippets.

@minjang
Last active November 28, 2016 19:42
Show Gist options
  • Save minjang/b6874b01eec8da032a2df511d1488e04 to your computer and use it in GitHub Desktop.
Save minjang/b6874b01eec8da032a2df511d1488e04 to your computer and use it in GitHub Desktop.
Applied only mem2reg pass
define linkonce_odr void @void temp_swap<int>(int&, int&)(i32* %a, i32* %b) #2 {
entry: ; %0
%0 = load i32, i32* %a, align 4 ; W %1
%1 = load i32, i32* %b, align 4 ; | W
store i32 %1, i32* %a, align 4 ; R |
store i32 %0, i32* %b, align 4 ; R
ret void
}
define linkonce_odr void @void xor_swap<int>(int&, int&)(i32* %a, i32* %b) #2 {
entry:
%0 = load i32, i32* %b, align 4
%1 = load i32, i32* %a, align 4
%xor = xor i32 %1, %0
store i32 %xor, i32* %a, align 4 ; %xor를 %a에 저장 후
%2 = load i32, i32* %a, align 4 ; 곧바로 %2로 읽음 => 중복
%3 = load i32, i32* %b, align 4
%xor1 = xor i32 %3, %2
store i32 %xor1, i32* %b, align 4 ; %xor를 %b에 저장 후
%4 = load i32, i32* %b, align 4 ; 곧바로 %4로 읽음 => 중복
%5 = load i32, i32* %a, align 4
%xor2 = xor i32 %5, %4
store i32 %xor2, i32* %a, align 4
ret void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment