Currently, the ASan executables built with -O0 are unnecessarily slow. The main reason is that ASan instrumentation pass inserts redundant checks around promotable allocas. These allocas do not get instrumented under -O1 because they get converted to virtual registered by mem2reg. With this patch, ASan instrumentation pass will only instrument non promotable allocas, giving us a speedup of 39% on a collection of benchmarks with -O0. (There is no measurable speedup at -O1.)
Comments/Questions:
- We've initially discussed creating another pass to annotate the uninteresting load and stores. However, the check is simple and having a separate pass seems like an overkill.
- A bunch of ASan llvm tests are written using promotable allocas. I've added volatile stores or marked the existing stores as volatile to make the allocas non-promotable.
- Two of the runtime tests also seem to depend on being run with -O0. With this modification, I am getting the same behavior as when the tests are run with higher optimization levels. I've turned off the mode on those tests since I am not sure if a better fix is available. They fail on comparing values returned by __asan_region_is_poisoned.
- Should "isInterestingAlloca()" be hoisted out of "FunctionStackPoisoner" and used in "isInterestingMemoryAccess"?
You will now execute all other if statements even if the first one is true. At leats change the following ifs to "else if", or preserve the structure with 'return' and have another function that checks isAllocaPromotable