Created
September 6, 2018 13:21
-
-
Save ysakasin/9663dcbba9f8c404a4c953ec13c58e25 to your computer and use it in GitHub Desktop.
mem2regを適用した例
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 = 'top' | |
source_filename = "top" | |
define i64 @main() { | |
entrypoint: | |
%x = alloca i64 | |
%y = alloca i64 | |
store i64 84, i64* %x | |
store i64 36, i64* %y | |
%0 = load i64, i64* %x | |
%1 = load i64, i64* %y | |
%2 = call i64 @gcd(i64 %0, i64 %1) | |
ret i64 %2 | |
} | |
define i64 @gcd(i64 %x, i64 %y) { | |
entry: | |
%x1 = alloca i64 | |
store i64 %x, i64* %x1 | |
%y2 = alloca i64 | |
store i64 %y, i64* %y2 | |
br label %while.cond | |
while.cond: ; preds = %if.merge4, %entry | |
%0 = load i64, i64* %x1 | |
%1 = load i64, i64* %y2 | |
%2 = icmp ne i64 %0, %1 | |
br i1 %2, label %while.body, label %while.merge | |
while.body: ; preds = %while.cond | |
%3 = load i64, i64* %x1 | |
%4 = load i64, i64* %y2 | |
%5 = icmp slt i64 %3, %4 | |
br i1 %5, label %if.then, label %if.merge | |
if.then: ; preds = %while.body | |
%6 = load i64, i64* %y2 | |
%7 = load i64, i64* %x1 | |
%8 = sub i64 %6, %7 | |
store i64 %8, i64* %y2 | |
br label %if.merge | |
if.merge: ; preds = %if.then, %while.body | |
%9 = load i64, i64* %y2 | |
%10 = load i64, i64* %x1 | |
%11 = icmp slt i64 %9, %10 | |
br i1 %11, label %if.then3, label %if.merge4 | |
if.then3: ; preds = %if.merge | |
%12 = load i64, i64* %x1 | |
%13 = load i64, i64* %y2 | |
%14 = sub i64 %12, %13 | |
store i64 %14, i64* %x1 | |
br label %if.merge4 | |
if.merge4: ; preds = %if.then3, %if.merge | |
br label %while.cond | |
while.merge: ; preds = %while.cond | |
%15 = load i64, i64* %x1 | |
ret i64 %15 | |
} |
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 = './gcd.ll' | |
source_filename = "top" | |
define i64 @main() { | |
entrypoint: | |
%0 = call i64 @gcd(i64 84, i64 36) | |
ret i64 %0 | |
} | |
define i64 @gcd(i64 %x, i64 %y) { | |
entry: | |
br label %while.cond | |
while.cond: ; preds = %if.merge4, %entry | |
%y2.0 = phi i64 [ %y, %entry ], [ %y2.1, %if.merge4 ] | |
%x1.0 = phi i64 [ %x, %entry ], [ %x1.1, %if.merge4 ] | |
%0 = icmp ne i64 %x1.0, %y2.0 | |
br i1 %0, label %while.body, label %while.merge | |
while.body: ; preds = %while.cond | |
%1 = icmp slt i64 %x1.0, %y2.0 | |
br i1 %1, label %if.then, label %if.merge | |
if.then: ; preds = %while.body | |
%2 = sub i64 %y2.0, %x1.0 | |
br label %if.merge | |
if.merge: ; preds = %if.then, %while.body | |
%y2.1 = phi i64 [ %2, %if.then ], [ %y2.0, %while.body ] | |
%3 = icmp slt i64 %y2.1, %x1.0 | |
br i1 %3, label %if.then3, label %if.merge4 | |
if.then3: ; preds = %if.merge | |
%4 = sub i64 %x1.0, %y2.1 | |
br label %if.merge4 | |
if.merge4: ; preds = %if.then3, %if.merge | |
%x1.1 = phi i64 [ %4, %if.then3 ], [ %x1.0, %if.merge ] | |
br label %while.cond | |
while.merge: ; preds = %while.cond | |
ret i64 %x1.0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment