ScalarEvolution: Suboptimal handling of globals

Hi,

For the program below, where “incr” and “Arr” are globals

What pass ordering are you using? If the "j += incr" expression incurs
a per-iteration load from @incr, then that can confuse SCEV. Loop
invariant code motion cleans it up.

With "opt -mem2reg -licm -S scev.ll | opt -analyze -scalar-evolution"
on the unoptimized IR generated by clang, I get:

...
  %j.0 = phi i32 [ 0, %6 ], [ %19, %18 ]
  --> {0,+,%3}<nsw><%9> Exits: <<Unknown>>

Thank you very much. -licm was what I had missing.

  • Vaivaswatha

What pass ordering are you using? If the “j += incr” expression incurs
a per-iteration load from @incr, then that can confuse SCEV. Loop
invariant code motion cleans it up.

With “opt -mem2reg -licm -S scev.ll | opt -analyze -scalar-evolution”
on the unoptimized IR generated by clang, I get:


%j.0 = phi i32 [ 0, %6 ], [ %19, %18 ]
→ {0,+,%3}<%9> Exits: <>