[LLVMdev] SCEV expression for ICmpInst

ether zhhb etherzhhb at gmail.com
Sat Apr 17 07:17:54 PDT 2010


Hi,

i am playing the ScalarEvolution these days. i found the the ScalarEvolution
will simply return a SCEVUnknow for a ICmpInst, so i think maybe great to
add a new kind of SCEV to the ScalarEvolution framework.


for example, if i run  ScalarEvolution on the bc file generate from the
following C source file:

int f(int a, int b, int c, int d) {
    return (2 * a + 5 * c + 2) > (4 * d - 3*b +3);
}

i will get a SCEVUnknow for the compare instruction, but it's great if i
could get something like 2 * a + 5 * c - 4 * d - 3*b - 1 > 0 for the compare
instruction :)


In my opinion, we need only 3 kind of SCEV expression to express the
ICmpInst: SCEVEqCond for equal condition,  SCEVNeCond for not equal
condition and SCEVGtCond for others. Because we can always transform A < B
to B > A, and transform A >= B to A > B - 1 (or A + 1> B), and A <= B to A <
B + 1 (or A - 1 < B). Furthermore, we can transform A > B to A - B > 0 and A
!= B to A - B != 0, so the SCEV for conditions will be very simple.

As there are already some functions such as "isKnownNonZero" in
ScalarEvolution, so we can compute these condition easily.

With the SCEV for conditions, we may write more meaningful code:

SCEVEQCond *S = SE.getCondition(some_icmp_instruction);

if (some_cond.isAlwaysTrue(SE))
  ... do some thing ...
else
  ... do some others thing ...

Dose this make sense? or i just make things unnecessarily complex?

any comment is appreciated.

--best regards
ether
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100417/78cb10aa/attachment.html>


More information about the llvm-dev mailing list