This change is for converting ‘sext of addrec’ to ‘addrec of sext’ when
compiler is sure transformation will not overflow.
By doing this will open opportunity for optimizations dependent on addRecExpr.
Consider below case:
for (j=1; j < itr; j++) {
for (i=1; i < itr; i++) { { temp= var[i * 2]; - - - - - }
}
“var[i * 2]” "SCEVAddRecExpr" is computable in *Outer Loop*
I expected Scalar evolution to get that, but it's not doing that
if ‘*2’ is transformed to shift reduction in some specific circumstances.
In the above example, ‘var[i * 2]’ is converted into ‘var[i << 1]’
by Instruction combiner (Shift reduction).
After this addRecExpr is not computable.
To fix that issue made changes in ScalarEvolution & SimplifyIndVar.
In ScalarEvolution converting ‘sext of addrec’ to ‘addrec of sext’ only when
Compiler is sure operation will not overflow:
i.e. (sext i32 Addrec{2,+,2}<nuw><%for.body4> to i64)
will be transformed into:
// addrec{(sext i32 '2' to i64),+,(sext i32 '2' to i64)}<nsw><%for.body4>
In “SimplifyIndVar.cpp” we strengthen overflow operation for left shift.
This needs to go in ScalarEvolution::getSignExtendExpr. There are a bunch of other rules for turning a sign extend of an add rec into an addrec there.