Don't invalidly eliminate certain stores of 0 to global/static variables.

This could happen in native-code peephole optimization if two stz instructions targeting different global/static locations occurred consecutively.

This was a regression introduced by commit a3170ea7.

The following program demonstrates the problem:

#pragma optimize 1+2+8+64
int i,j=1;
int main (void) {
    i = 0;
    j = 0;
    return j; /* should return 0 */
}
This commit is contained in:
Stephen Heumann 2017-12-13 20:03:48 -06:00
parent 4e7a7e67e7
commit 5312843b93
1 changed files with 10 additions and 7 deletions

View File

@ -1740,13 +1740,16 @@ var
{ kws }
{ stz $xx, stz $xx }
m_stz_abs, m_stz_absX, m_stz_dir, m_stz_dirX:
if npeep[ns].opcode = npeep[ns+1].opcode then begin
if npeep[ns].operand = npeep[ns+1].operand then begin
Remove(ns+1)
end; {if}
end; {if}
m_stz_abs, m_stz_absX:
if npeep[ns].opcode = npeep[ns+1].opcode then
if npeep[ns].operand = npeep[ns+1].operand then
if npeep[ns].name = npeep[ns+1].name then
Remove(ns+1);
m_stz_dir, m_stz_dirX:
if npeep[ns].opcode = npeep[ns+1].opcode then
if npeep[ns].operand = npeep[ns+1].operand then
Remove(ns+1);
otherwise: ;