Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect "kill" logic in copy propagation #7

Open
wants to merge 1 commit into
base: arm
Choose a base branch
from

Conversation

PiNengShaoNian
Copy link

int add(int n)
{
    int a, b;
    b = n;
    a = b;
    n = 3;
    return a;
}

考虑上面的代码如果在对n = 3进行复写传播时只是简单的只将b = n杀死的话那么在对return a进行覆写传播时就会复用本应该被杀死的语句a = b(先前已被复写传播简化为a = n)导致return a中的a会被替换为字面量3这明显是错误的,所以我们在这里保守的杀死一个联通分量中的所有语句。


修改前产生的中间代码(错误的):

-------------<add>Start--------------
entry
return 3 goto .L1
.L1:
exit
--------------<add>End---------------
编译完成:错误=0,警告=0.

修改后产生的中间代码:

-------------<add>Start--------------
entry
dec a
a = n
return a goto .L1
.L1:
exit
--------------<add>End---------------
编译完成:错误=0,警告=0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant