This is an archive of the discontinued LLVM Phabricator instance.

[BPF] Fix a recursion bug in BPF Peephole ZEXT optimization
ClosedPublic

Authored by yonghong-song on Nov 22 2019, 12:33 AM.

Details

Summary

Commit a0841dfe8594 ("[BPF] Fix a bug in peephole optimization")
fixed a bug in peephole optimization. Recursion is introduced
to handle COPY and PHI instructions.

Unfortunately, multiple PHI instructions may form a cycle
and this will cause infinite recursion, eventual segfault.
For Commit a0841dfe8594, I indeed tried a few loops to ensure
that I won't see the recursion, but I did not try with
complex control flows, which, as demonstrated with the test case
in this patch, may introduce PHI cycles.

This patch fixed the issue by introducing a set to remember
visited PHI instructions. This way, cycles can be properly
detected and handled.

Diff Detail

Event Timeline

yonghong-song created this revision.Nov 22 2019, 12:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 22 2019, 12:33 AM
ast accepted this revision.Nov 22 2019, 12:43 AM
This revision is now accepted and ready to land.Nov 22 2019, 12:43 AM
This revision was automatically updated to reflect the committed changes.