[msan] Optimize getOriginPtr.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Thu, 29 Nov 2012 13:43:05 +0000 (13:43 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Thu, 29 Nov 2012 13:43:05 +0000 (13:43 +0000)
Rewrite getOriginPtr in a way that lets subsequent optimizations factor out
the common part of Shadow and Origin address calculation. Improves perf by
up to 5%.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168879 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/MemorySanitizer.cpp

index ed0f89bfb590af0cbb3e7747facead5ce9009e96..8cc0084db59281e4e6f9355a73edcd0dcad1e882 100644 (file)
@@ -503,15 +503,16 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
   /// address.
   ///
   /// OriginAddr = (ShadowAddr + OriginOffset) & ~3ULL
-  ///            = Addr & (~ShadowMask & ~3ULL) + OriginOffset
   Value *getOriginPtr(Value *Addr, IRBuilder<> &IRB) {
     Value *ShadowLong =
       IRB.CreateAnd(IRB.CreatePointerCast(Addr, MS.IntptrTy),
-                    ConstantInt::get(MS.IntptrTy, ~MS.ShadowMask & ~3ULL));
+                    ConstantInt::get(MS.IntptrTy, ~MS.ShadowMask));
     Value *Add =
       IRB.CreateAdd(ShadowLong,
                     ConstantInt::get(MS.IntptrTy, MS.OriginOffset));
-    return IRB.CreateIntToPtr(Add, PointerType::get(IRB.getInt32Ty(), 0));
+    Value *SecondAnd =
+      IRB.CreateAnd(Add, ConstantInt::get(MS.IntptrTy, ~3ULL));
+    return IRB.CreateIntToPtr(SecondAnd, PointerType::get(IRB.getInt32Ty(), 0));
   }
 
   /// \brief Compute the shadow address for a given function argument.