[PATCH] Implement variable-sized alloca instrumentation.

Yury Gribov tetra2005 at gmail.com
Wed Nov 19 00:06:16 PST 2014


================
Comment at: lib/Transforms/Instrumentation/AddressSanitizer.cpp:656
@@ +655,3 @@
+                                                       Int32PtrTy);
+    // if (PartialSize) {
+    //   PartialRzMagic = calculatePartialRzMagic(PartialSize);
----------------
kcc wrote:
> m.ostepenko wrote:
> > kcc wrote:
> > > instead of creating a new BB for partial RZ, I would do this: 
> > > make sure that PartialSize is never zero, i.e. instead of being in 0..31 it is in 1..32
> > > This is better as we will not need to keep both pointers (PartialRz and RightRz) alive throughout the procedure. 
> > Yes, this is a good idea to avoid new BB creation. But we still need both PartialRz and RightRz, because in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32, isn't it?
> > 
> > Or maybe I've misunderstood something?
> >>But we still need both PartialRz and RightRz, because in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32, isn't it?
> There are two ways to implement this: 
> 
> 1. in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32
> In this case, we need to poison both PartialRz and RightRz and we need to keep this value in the register for the entire function. 
> 
> 2. PartialRz is always strictly before RightRz. 
> In this case we always unpoison RightRz and RightRz-32 and so we don't need to keep PartialRz around. 
> 
> It's hard to tell which is better w/o measuring on a good benchmark, also there is a memory-vs-cpu tradeoff (larger redzones vs larger register pressure). 
> But the second way sounds slightly better to me. 
> 
> 
>> in case of PartialSize == 32 PartialRz points the same address as RightRz, otherwise RightRz == PartialSize + 32
> 
> In this case ... we need to keep this value in the register for the entire function

Not really, we can do the same as in your case 2 i.e. zero out RightRz - 32. Worst case (when PartialRz = RightRz) we'll do a redundant write.

As for benchmarking I'm not sure it matters that much - allocas are quite rare anyway.

http://reviews.llvm.org/D6055






More information about the llvm-commits mailing list