Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ramntry
Created May 15, 2018 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramntry/f3aa15e826660bebc94d0acc59dfd29d to your computer and use it in GitHub Desktop.
Save ramntry/f3aa15e826660bebc94d0acc59dfd29d to your computer and use it in GitHub Desktop.
define i64 @test_phi_loop(i32 %n) {
entry:
br label %loop
loop:
%counter = phi i32 [ %n, %entry ], [ %counter.dec, %loop ]
%elem = phi { i64, i64 } [ { i64 0, i64 1 }, %entry ], [ %updated, %loop ]
%prev = extractvalue { i64, i64 } %elem, 0
%curr = extractvalue { i64, i64 } %elem, 1
%next = add i64 %prev, %curr
%shifted = insertvalue { i64, i64 } %elem, i64 %curr, 0
%updated = insertvalue { i64, i64 } %shifted, i64 %next, 1
%counter.dec = sub i32 %counter, 1
%cond = icmp sle i32 %counter, 0
br i1 %cond, label %exit, label %loop
exit:
%res = extractvalue { i64, i64 } %elem, 0
ret i64 %res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment