Skip to content

Instantly share code, notes, and snippets.

@minjang
Last active November 28, 2016 23:03
Show Gist options
  • Save minjang/4b41864b6081dbeba2dd8f2b37a046ca to your computer and use it in GitHub Desktop.
Save minjang/4b41864b6081dbeba2dd8f2b37a046ca to your computer and use it in GitHub Desktop.
Applied mem2reg and gvn 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 = xor i32 %1, %0 ; W
store i32 %xor, i32* %a, align 4 ; R
%2 = load i32, i32* %b, align 4 ; | %xor1
%xor1 = xor i32 %2, %xor ; R W
store i32 %xor1, i32* %b, align 4 ; R
%3 = load i32, i32* %a, align 4 ; | %xor2
%xor2 = xor i32 %3, %xor1 ; R W
store i32 %xor2, i32* %a, align 4 ; R
ret void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment