[llvm-dev] Optimize placement of llvm.lifetime.start/end

Markus Lavin via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 29 00:11:56 PDT 2018


Does (or should) LLVM make any attempt to optimize the placement of llvm.lifetime.start and llvm.lifetime.end intrinsics?
Considering the example below (where the pointer argument to function bar ends up being marked as nocapture in IR) the stack usage is twice of what would be necessary since the lifetime markers for mem1 and mem2 indicate that they are both live at the same time. The markers seem to remain where they were placed by clang while I naively expected that opt would try to adjust them to allow for better stack coloring.

#define LEN 512

void bar(__attribute__((noescape)) int *p)  ;

int foo(void)
{
  int sum1 = 0, sum2 = 0;

    int mem1[LEN];
    bar(mem1);
    for (int i = 0; i < LEN; i++)
      sum1 += mem1[i];

    int mem2[LEN];
    bar(mem2);
    for (int i = 0; i < LEN; i++)
      sum2 += mem2[i];

  return sum1 + sum2;
}

-Markus


More information about the llvm-dev mailing list