aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorDávid Bolvanský <david.bolvansky@gmail.com>2021-04-20 02:03:38 +0200
committerDávid Bolvanský <david.bolvansky@gmail.com>2021-04-20 02:04:18 +0200
commit324d641b75b54a8772c3c9a881eedad62dc5518c (patch)
tree9621b948b6c997630828572a69a0adebbc9e373f /llvm/lib
parenta2cd6d07691a645bfb8fb5eeeba2eb5970312c7f (diff)
downloadllvm-324d641b75b54a8772c3c9a881eedad62dc5518c.zip
llvm-324d641b75b54a8772c3c9a881eedad62dc5518c.tar.gz
llvm-324d641b75b54a8772c3c9a881eedad62dc5518c.tar.bz2
[InstCombine] Enhance deduction of alignment for aligned_alloc
This patch improves https://reviews.llvm.org/D76971 (Deduce attributes for aligned_alloc in InstCombine) and implements "TODO" item mentioned in the review of that patch. > The function aligned_alloc() is the same as memalign(), except for the added restriction that size should be a multiple of alignment. Currently, we simply bail out if we see a non-constant size - change that. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D100785
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp14
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineInternal.h1
2 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 615f10e..3932446 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2049,7 +2049,7 @@ static IntrinsicInst *findInitTrampoline(Value *Callee) {
return nullptr;
}
-static void annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI) {
+void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI) {
unsigned NumArgs = Call.getNumArgOperands();
ConstantInt *Op0C = dyn_cast<ConstantInt>(Call.getOperand(0));
ConstantInt *Op1C =
@@ -2068,12 +2068,14 @@ static void annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI) {
Call.addAttribute(AttributeList::ReturnIndex,
Attribute::getWithDereferenceableOrNullBytes(
Call.getContext(), Op0C->getZExtValue()));
- } else if (isAlignedAllocLikeFn(&Call, TLI) && Op1C) {
- Call.addAttribute(AttributeList::ReturnIndex,
- Attribute::getWithDereferenceableOrNullBytes(
- Call.getContext(), Op1C->getZExtValue()));
+ } else if (isAlignedAllocLikeFn(&Call, TLI)) {
+ if (Op1C)
+ Call.addAttribute(AttributeList::ReturnIndex,
+ Attribute::getWithDereferenceableOrNullBytes(
+ Call.getContext(), Op1C->getZExtValue()));
// Add alignment attribute if alignment is a power of two constant.
- if (Op0C && Op0C->getValue().ult(llvm::Value::MaximumAlignment)) {
+ if (Op0C && Op0C->getValue().ult(llvm::Value::MaximumAlignment) &&
+ isKnownNonZero(Call.getOperand(1), DL, 0, &AC, &Call, &DT)) {
uint64_t AlignmentVal = Op0C->getZExtValue();
if (llvm::isPowerOf2_64(AlignmentVal))
Call.addAttribute(AttributeList::ReturnIndex,
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 8907d4b..edf8f0f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -187,6 +187,7 @@ public:
const Twine &Suffix = "");
private:
+ void annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI);
bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
bool shouldChangeType(Type *From, Type *To) const;
Value *dyn_castNegVal(Value *V) const;