[PATCH] IndVarSimplify : do not recompute an IV value used outside of the loop if it is trivially known not to be beneficial

Arnaud A. de Grandmaison arnaud.adegm at gmail.com
Thu Feb 28 02:15:12 PST 2013


Hi All,

I believe the IndVarSimplify is a bit too aggressive when it computes
exit values. There are some cases where it is not beneficial to do so.
For example, in the code below :

extern void func(unsigned val);

void test(unsigned m)
{
  unsigned a = 0;

  for (int i=0; i<186; i++) {
    a += m;
    func(a);
  }

  func(a);
}

Although the value of 'a' can be computed outside of the loop, there is
no benefit in recomputing it : it is already computed and used in the
loop in a way that can not be optimized away. When compiling the above
testcase  with clang on x86, we get an unnecessary multiply.

Detecting (non) optimizable patterns is way to difficult, but we can
still grasp some low hanging fruits if we can trivially determine there
is no benefit.

Comments ?

Cheers,

-- 
Arnaud A. de Grandmaison

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-IndVarSimplify-do-not-recompute-an-IV-value-outside-.patch
Type: text/x-patch
Size: 3443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130228/b7f14313/attachment.bin>


More information about the llvm-commits mailing list