Skip to content

Commit

Permalink
[IR] Fix getPointerAlignment for CallBase
Browse files Browse the repository at this point in the history
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
  • Loading branch information
uenoku committed Jul 28, 2019
1 parent cc0a4cd commit afd4a37
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions llvm/lib/IR/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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();
Expand Down

0 comments on commit afd4a37

Please sign in to comment.