[PATCH] Skip promotable allocas to improve performance at -O0

Anna Zaks zaks.anna at gmail.com
Mon Feb 23 15:45:48 PST 2015


The purpose of this patch is to only remove checks for accesses that are known to be safe. All array accesses are still getting checked. For example, in the following code snippet, only stores/loads to idx will not be checked:
char test_promotable_allocas() {

  char r[3];
  char a[3];
  int idx = 10;
  a[10] = 0;
  r[idx] = 10;
  return a[10] + r[idx];

}

Here is the relevant code from isAllocaPromotable:
else if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(U)) {

  if (GEPI->getType() != Type::getInt8PtrTy(U->getContext(), AS))
    return false;
  if (!GEPI->hasAllZeroIndices())
    return false;
  if (!onlyUsedByLifetimeMarkers(GEPI))
    return false;

On Thu, Feb 19, 2015 at 6:59 PM, Chandler Carruth <chandlerc at google.com> wrote:

> I don't really like this approach because it will introduce false negatives. We have even been helped in >debugging "miscompiles" of incorrect code by running asan at -O0 to point out where the stack variables.


Chandler, are there specific cases you are worried about here? False negatives are possible at higher optimization levels (and your proposed approach to solve them sounds reasonable); with this patch, I am not trying to get parity with -O1, but just reduce the number of unnecessary checks.

Sorry for the delayed response - I was on vacation late last week.


http://reviews.llvm.org/D7741

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list