Skip to content

Add effective peephole optimizer for uop traces. #152215

Description

@markshannon

Feature or enhancement

Currently we lack an effective peephole optimizer for uops traces.
We do some ad-hoc removal of LOAD/POP pairs, but many enhancements are missed.

For example, this silly program:

def add(a, b):
    return a + b

def loop(n=100_000):
    t = 0
    for _ in range(n):
        t += add(1,2)

if __name__ == "__main__":
    loop()

generates this trace:

Image

which contains the sequence:

_LOAD_FAST_BORROW 0
_LOAD_FAST_BORROW_1
_LOAD_CONST_INLINE_BORROW K 
_RROT_3
_POP_TOP_NOP
_POP_TOP_NOP

which should be reduced to

_LOAD_CONST_INLINE_BORROW K 

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions