Skip to content

Commit 8604e56

Browse files
committed
Add test code
1 parent 3918a94 commit 8604e56

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Lib/test/test_peepholer.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,5 +1083,52 @@ def test_no_unsafe_static_swap(self):
10831083
]
10841084
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)
10851085

1086+
def test_dead_store_elimination_in_same_lineno(self):
1087+
insts = [
1088+
('LOAD_CONST', 0, 1),
1089+
('LOAD_CONST', 1, 2),
1090+
('LOAD_CONST', 2, 3),
1091+
('SWAP', 3, 4),
1092+
('STORE_FAST', 1, 4),
1093+
('STORE_FAST', 1, 4),
1094+
('STORE_FAST', 1, 4),
1095+
('RETURN_VALUE', 5)
1096+
]
1097+
expected_insts = [
1098+
('LOAD_CONST', 0, 1),
1099+
('LOAD_CONST', 1, 2),
1100+
('LOAD_CONST', 2, 3),
1101+
('SWAP', 3, 4),
1102+
('POP_TOP', 0, 4),
1103+
('POP_TOP', 0, 4),
1104+
('STORE_FAST', 1, 4),
1105+
('RETURN_VALUE', 5)
1106+
]
1107+
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)
1108+
1109+
def test_no_dead_store_elimination_in_different_lineno(self):
1110+
insts = [
1111+
('LOAD_CONST', 0, 1),
1112+
('LOAD_CONST', 1, 2),
1113+
('LOAD_CONST', 2, 3),
1114+
('SWAP', 3, 4),
1115+
('STORE_FAST', 1, 4),
1116+
('STORE_FAST', 1, 5),
1117+
('STORE_FAST', 1, 6),
1118+
('RETURN_VALUE', 5)
1119+
]
1120+
expected_insts = [
1121+
('LOAD_CONST', 0, 1),
1122+
('LOAD_CONST', 1, 2),
1123+
('LOAD_CONST', 2, 3),
1124+
('SWAP', 3, 4),
1125+
('STORE_FAST', 1, 4),
1126+
('STORE_FAST', 1, 5),
1127+
('STORE_FAST', 1, 6),
1128+
('RETURN_VALUE', 5)
1129+
]
1130+
self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1)
1131+
1132+
10861133
if __name__ == "__main__":
10871134
unittest.main()

0 commit comments

Comments
 (0)