aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorDávid Bolvanský <david.bolvansky@gmail.com>2021-04-23 10:11:59 +0200
committerDávid Bolvanský <david.bolvansky@gmail.com>2021-04-23 11:07:14 +0200
commitc2297544c04764237cedc523083c7be2fb3833d4 (patch)
treeaeed25cff18aee55c82c822db906552732d14863 /clang/lib/CodeGen/CGCall.cpp
parenta819e7339315687f06f686971a649f614afbd987 (diff)
downloadllvm-c2297544c04764237cedc523083c7be2fb3833d4.zip
llvm-c2297544c04764237cedc523083c7be2fb3833d4.tar.gz
llvm-c2297544c04764237cedc523083c7be2fb3833d4.tar.bz2
[Clang] Propagate guaranteed alignment for malloc and others
LLVM should be smarter about *known* malloc's alignment and this knowledge may enable other optimizations. Originally started as LLVM patch - https://reviews.llvm.org/D100862 but this logic should be really in Clang. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D100879
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 366c83e..6c77f18 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2048,6 +2048,24 @@ void CodeGenModule::ConstructAttributeList(
// allows it to work on indirect virtual function calls.
if (AttrOnCallSite && TargetDecl->hasAttr<NoMergeAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoMerge);
+
+ // Add known guaranteed alignment for allocation functions.
+ if (unsigned BuiltinID = Fn->getBuiltinID()) {
+ switch (BuiltinID) {
+ case Builtin::BIaligned_alloc:
+ case Builtin::BIcalloc:
+ case Builtin::BImalloc:
+ case Builtin::BImemalign:
+ case Builtin::BIrealloc:
+ case Builtin::BIstrdup:
+ case Builtin::BIstrndup:
+ RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() /
+ Context.getTargetInfo().getCharWidth());
+ break;
+ default:
+ break;
+ }
+ }
}
// 'const', 'pure' and 'noalias' attributed functions are also nounwind.