LLVMdev Digest, Vol 50, Issue 33

7 for(i=0; i<j && i+j+1<N; i++) {

8 for(i=0; i<j && i<N-j-1; i++) {

Line 7 and Line 8 actually have the same expression,
    
The expressions are logically similar, but they aren't the same to the compiler unless some pass that recognizes these types of polynomial equations and can prove that they are the same is run (I'm not sure if such a pass exists in LLVM). For instance, because you use "j - 1" in 8, you now have a situation where you have a negative number when j == 0, etc.
  

ok, i see.

  

Line 8 just move the "j+1" to the right hand of the inequation.

I just wonder why the two equal inequation result in different cfg, the
additional basicblock, backedge...
Surely the two cfg are all correct, but just the additional backedge
makes it hard for loop pipeline.

Can we improve it?

For what it's worth, I got the exact same code for both forms when compiling at -O3.
  

I also tried -O3, but got different ll code, what llvm revision are you using ?

Top of tree.

-bw