HomePhabricator

[DSE] Eliminates redundant store of an exisiting value (PR16520)

Authored by yurai007 on Oct 22 2021, 5:11 AM.

Description

[DSE] Eliminates redundant store of an exisiting value (PR16520)

That's https://reviews.llvm.org/D90328 follow-up.

This change eliminates writes to variables where the value that is being written is already stored in the variable.
This achieves the goal by looping through all memory definitions in the current state and getting defining access from each of them.
When there is defining access where the write instruction is identical to the original instruction it will remove this redundant write.

For example:

void f() {

x = 1;
if foo() {

x = 1;
g();

} else {

h();

}

}
void g();
void h();

The second x=1 will be eliminated since it is rewriting 1 to x. This pass will produce this:

void f() {

x = 1;
if foo() {

g();

} else {

h();

}

}
void g();
void h();

Differential Revision: https://reviews.llvm.org/D111727