From: Hideto Ueno Date: Sun, 28 Jul 2019 06:17:46 +0000 (+0000) Subject: [IR] Fix getPointerAlignment for CallBase X-Git-Tag: llvmorg-11-init~13415 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afd4a37b2a35d730a85a26d21428034915bd5b3f;p=platform%2Fupstream%2Fllvm.git [IR] Fix getPointerAlignment for CallBase Summary: In current getPointerAlignemnt implementation, CallBase.getPointerAlignement(..) checks only parameter attriutes in the callsite. For example, ``` declare align 8 i8* @foo() define void @bar() { %a = tail call align 8 i8* @foo() ; getPointerAlignment returns 8 %b = tail call i8* @foo() ; getPointerAlignemnt returns 0 ret void } ``` This patch will fix the problem. Reviewers: jdoerfert Reviewed By: jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65281 llvm-svn: 367185 --- diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 6a743b7..c0efab4 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -723,9 +723,11 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const { if (AllocatedType->isSized()) Align = DL.getPrefTypeAlignment(AllocatedType); } - } else if (const auto *Call = dyn_cast(this)) - Align = Call->getAttributes().getRetAlignment(); - else if (const LoadInst *LI = dyn_cast(this)) + } else if (const auto *Call = dyn_cast(this)) { + Align = Call->getRetAlignment(); + if (Align == 0 && Call->getCalledFunction()) + Align = Call->getCalledFunction()->getAttributes().getRetAlignment(); + } else if (const LoadInst *LI = dyn_cast(this)) if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { ConstantInt *CI = mdconst::extract(MD->getOperand(0)); Align = CI->getLimitedValue();