[PATCH] D65281: [IR] Fix getPointerAlignment for CallBase
Hideto Ueno via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 06:59:09 PDT 2019
uenoku created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
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.
https://reviews.llvm.org/D65281
Files:
llvm/lib/IR/Value.cpp
Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -726,9 +726,11 @@
if (AllocatedType->isSized())
Align = DL.getPrefTypeAlignment(AllocatedType);
}
- } else if (const auto *Call = dyn_cast<CallBase>(this))
- Align = Call->getAttributes().getRetAlignment();
- else if (const LoadInst *LI = dyn_cast<LoadInst>(this))
+ } else if (const auto *Call = dyn_cast<CallBase>(this)) {
+ Align = Call->getRetAlignment();
+ if (Align == 0 && Call->getCalledFunction())
+ Align = Call->getCalledFunction()->getAttributes().getRetAlignment();
+ } else if (const LoadInst *LI = dyn_cast<LoadInst>(this))
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
Align = CI->getLimitedValue();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65281.211738.patch
Type: text/x-patch
Size: 907 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190725/d9227d86/attachment.bin>
More information about the llvm-commits
mailing list