[asan] small optimization: do not emit "x+0" instructions
authorKostya Serebryany <kcc@google.com>
Fri, 27 Apr 2012 10:04:53 +0000 (10:04 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 27 Apr 2012 10:04:53 +0000 (10:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155701 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp

index 33b56d503653ad0b9dc620d4f83df668c83d5202..b01cdbf680a2fe1ab301854c54f36b2062e35291 100644 (file)
@@ -363,11 +363,12 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
   size_t Granularity = 1 << MappingScale;
   if (TypeSize < 8 * Granularity) {
     // Addr & (Granularity - 1)
   size_t Granularity = 1 << MappingScale;
   if (TypeSize < 8 * Granularity) {
     // Addr & (Granularity - 1)
-    Value *Lower3Bits = IRB2.CreateAnd(
+    Value *LastAccessedByte = IRB2.CreateAnd(
         AddrLong, ConstantInt::get(IntptrTy, Granularity - 1));
     // (Addr & (Granularity - 1)) + size - 1
         AddrLong, ConstantInt::get(IntptrTy, Granularity - 1));
     // (Addr & (Granularity - 1)) + size - 1
-    Value *LastAccessedByte = IRB2.CreateAdd(
-        Lower3Bits, ConstantInt::get(IntptrTy, TypeSize / 8 - 1));
+    if (TypeSize / 8 > 1)
+      LastAccessedByte = IRB2.CreateAdd(
+          LastAccessedByte, ConstantInt::get(IntptrTy, TypeSize / 8 - 1));
     // (uint8_t) ((Addr & (Granularity-1)) + size - 1)
     LastAccessedByte = IRB2.CreateIntCast(
         LastAccessedByte, IRB.getInt8Ty(), false);
     // (uint8_t) ((Addr & (Granularity-1)) + size - 1)
     LastAccessedByte = IRB2.CreateIntCast(
         LastAccessedByte, IRB.getInt8Ty(), false);