LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 32998 - [Polly - AST Generation] Derive knowledge about loops that are known to be executed at least once
Summary: [Polly - AST Generation] Derive knowledge about loops that are known to be ex...
Status: NEW
Alias: None
Product: Polly
Classification: Unclassified
Component: isl (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Polly Development Mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-10 23:39 PDT by Tobias Grosser
Modified: 2017-05-10 23:39 PDT (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Grosser 2017-05-10 23:39:50 PDT
Polly generates in lib/CodeGen/LoopGenerators.cpp:createLoop one of the two loop forms:


//              BeforeBB                      BeforeBB                           
//                 |                             |                               
//                 v                             v                               
//              GuardBB                      PreHeaderBB                         
//              /      |                         |   _____                       
//     __  PreHeaderBB  |                        v  \/    |                      
//    /  \    /         |                     HeaderBB  latch                    
// latch  HeaderBB      |                        |\       |                      
//    \  /    \         /                        | \------/                      
//     <       \       /                         |                               
//              \     /                          v                               
//              ExitBB                         ExitBB   


In C, this means a loop:

for (i = LB; i <= UB; i++)
   S(i);

is generated either as:

if (LB <= UB) {
  long i = LB;
  do {
   S(i);
   i++;
  } while (LB <= UB);
}

or as

  long i = LB;
  do {
   S(i);
   i++;
  } while (LB <= UB);

in case we can statically proof that LB <= UB. Polly can do this only for integer constants, but isl can likely proof this information a lot more often. It would be great if isl can provide this information, such that we can avoid code size increase due to the unnecessary condition. The condition likely also hinders loop invariant code motion.

Background: Polly (and LLVM in general) does this rewriting to move branches after the loop body, such that the content of the loop body can be hoisted out of the loop without any control flow branches blocking this hoisting.