Skip to content

Support constant hints inside scf.For #578

@johnzl-777

Description

@johnzl-777

Currently constant propagation does not apply hints to invariant elements inside of loops.

This is a bit of a contrived example (not mean to be an actual user pattern) from bloqade-circuit but gets my point across:

    @squin.kernel(fold=True)
    def test():
        qs = squin.qalloc(3)
        for _ in range(5):
            m = qs[0]
            squin.measure(m)
    
    test.print(hint="const")

Shows that inside the loop, you'd see something like:

%3 = py.constant.constant 0 : !py.int // hint<const=missing>

The necessity of this is driven primarily by the fact that for my work on supporting translation from scf.For to stim's REPEAT in bloqade-circuit requires measurement ID analysis to go into the loop body. Without the constant hint data about things like the integers for indexing into things (which get lowered to getitem statements) the analysis falls back to the bottom lattice type.

The ability to figure out what is invariant would have to be identical to what has to happen for scf.For -> stim.repeat: you would need to go through the loop multiple times and figure out what values would be safe to assign a hint to.

This is not a blocking issue for me (@weinbe58 first pointed out the necessity + solution to this, as well as a workaround I can do where I just introducing my own lattice element to carry constant info around) but it seems like there are other places where this might be necessary

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect:scfstructural control flow related issueenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions