diff options
| author | Vedant Kumar <vsk@apple.com> | 2017-10-03 01:27:26 +0000 |
|---|---|---|
| committer | Vedant Kumar <vsk@apple.com> | 2017-10-03 01:27:26 +0000 |
| commit | a8ff3b3528a0027e0b937d8c2a03c31c66f6a970 (patch) | |
| tree | 9f98dc17dac2fec8dc4758955a2101a44860ad4f /clang/lib | |
| parent | 791f70115b262406960e4862ea15aa3b41dc5423 (diff) | |
| download | bcm5719-llvm-a8ff3b3528a0027e0b937d8c2a03c31c66f6a970.tar.gz bcm5719-llvm-a8ff3b3528a0027e0b937d8c2a03c31c66f6a970.zip | |
[ubsan] Skip alignment checks which are folded away
Don't emit alignment checks which the IR constant folder throws away.
I've tested this out on X86FastISel.cpp. While this doesn't decrease
end-to-end compile-time significantly, it results in 122 fewer type
checks (1% reduction) overall, without adding any real complexity.
Differential Revision: https://reviews.llvm.org/D37544
llvm-svn: 314752
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index e87c4a9e2ed..cd2e8e14bc6 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -618,6 +618,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, auto PtrToAlloca = dyn_cast<llvm::AllocaInst>(Ptr->stripPointerCastsNoFollowAliases()); + llvm::Value *True = llvm::ConstantInt::getTrue(getLLVMContext()); llvm::Value *IsNonNull = nullptr; bool IsGuaranteedNonNull = SkippedChecks.has(SanitizerKind::Null) || PtrToAlloca; @@ -629,8 +630,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, // The IR builder can constant-fold the null check if the pointer points to // a constant. - IsGuaranteedNonNull = - IsNonNull == llvm::ConstantInt::getTrue(getLLVMContext()); + IsGuaranteedNonNull = IsNonNull == True; // Skip the null check if the pointer is known to be non-null. if (!IsGuaranteedNonNull) { @@ -684,7 +684,8 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1)); llvm::Value *Aligned = Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0)); - Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment)); + if (Aligned != True) + Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment)); } } |

