Lunderberg opened a new pull request, #14951:
URL: https://github.com/apache/tvm/pull/14951

   Prior to this commit, any trivial let binding of `var1 = var2` is inlined.  
However, buffer definitions are not updated, so this can result in dangling 
`tir::Var` instances.  This commit updates the `tir.Simplify` pass to keep 
trivial let bindings if they are used as part of a buffer definition.
   
   Ideally, the trivial `LetStmt` variable would be inlined into the buffer 
definition as well as other expressions.  However, because a buffer may be 
implicitly declared, the first usage may be within a constrained context.  If 
that happens, the simplified shape/strides expression cannot be used to update 
the buffer definition, as that simplification is not valid at all possible 
usage points of the buffer.
   
   ```python
   for i in range(n):
       elem_offset = i
       view = T.Buffer(1, data=buf, elem_offset = elem_offset)
       if i == 0:
           # First occurrence in TIR is here, where elem_offset would
           # simplify to zero.
           view[0] = 1
       else:
           # But the same buffer is used here, where elem_offset doesn't
           # simplify to zero.
           view[0] = 2
   ```
   
   This will be resolvable after https://github.com/apache/tvm/pull/14778 
lands, requiring all buffers to be declared with `DeclBuffer` prior to usage.
   
   ```python
   for i in range(n):
       elem_offset = i
       # All variables used by the DeclBuffer are valid across the entire
       # body of the DeclBuffer.
       view = T.decl_buffer(1, data=buf, elem_offset = elem_offset)
       if i == 0:
           view[0] = 1
       else:
           view[0] = 2
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to