ANSHUMAN87 commented on pull request #6066:
URL: https://github.com/apache/incubator-tvm/pull/6066#issuecomment-663817727


   > This is a limited case of "loop unswitching". Please consider a more 
general solution, where
   > 
   > ```
   > for (i = 0..N) {
   >   // statement A
   >   if (invariant-condition) {
   >     // statement B
   >   } else {
   >     // statement C
   >   }
   >   // statement D
   > }
   > ```
   > 
   > is transformed into
   > 
   > ```
   > if (invariant-condition) {
   >   for (i = 0..N) {
   >     // statement A
   >     // statement B
   >     // statement D
   >   }
   > } else {
   >   for (i = 0..N) {
   >     // statement A
   >     // statement C
   >     // statement D
   >   }
   > }
   > ```
   > 
   > Using the same logic you could unswitch attribute statements, if needed.
   
   Thanks for bringing up this point!
   In fact this is on my top TODO list once current PR is merged.
   Here it is not the question of general solution, it is about covering more 
scenarios.
   Current changes covers most of the real-time scenarios (excluding 
hypothetical scenarios).
   This scenario is currently left uncovered intentionally because of following 
challenges.
   
   1. Invariant identification: What is the best way to identify the if 
condition variables are not updated inside the block ?
        For example in below case, how we can find out `var n` is invariant in 
the loop block:
   ```
       var n = 3
       for (i: int32, 0, n: int32) {
         if @tir.likely((n > 23), dtype=bool) {
           n = n + 2      
           data[i] = i
         } else {
           n = n + 3
           data[i] = i + 1
         }
       }
   
   ```
   
   2. Scope identification: Need to scan each and every statement to do this, 
where logic  becomes significantly more complex.
   
   May be we can discuss more about first Challenge. Please suggest if anyone 
has any optimum solution for it. 
   Let me know in case the scenario is not clear. TIA!
   


----------------------------------------------------------------
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.

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


Reply via email to