sdiv in array subscript

Hi llvm-dev,

Looks like currently ScalarEvolution will give up if there is a sdiv in array subscript, e.g.

int i;

A[i * 64 / 2]

in this case ScalarEvolution will just return an unknown for (i * 64 / 2).

For this case, InstCombine will do the jobs, but in general, is there a pass to deal with the sdiv here? like replace sdiv by udiv based on the range of “i”?

Thanks
Hongbin

Instcombine will replace sdiv with udiv if it can prove the sign bit is zero, but it isn't very good at analyzing induction variables; we might be able to improve that.

There are also some related transforms in lib/Transforms/Utils/SimplifyIndVar.cpp.

-Eli

Hi Eli,

Thanks. Do you mean ideally we should extend SimplifyIndVar to do the sdiv->udiv replacement?

Thanks
Hongbin

I haven't really looked into it closely, but it seems to make sense.

-Eli

Hi Eli,

Thanks. Do you mean ideally we should extend SimplifyIndVar to do the
sdiv->udiv replacement?

I haven't really looked into it closely, but it seems to make sense.

Ok.

Once I extend SimplifyIndVar, e.g. the simplifyUsersOfIV function. How I
can add a regression test for the extension? simplifyUsersOfIV is not a
pass.

Thanks
Hongbin

It gets called by -indvars. -Eli

Hi Eli,

I create a patch at https://reviews.llvm.org/D31488

Thanks
Hongbin