[llvm] r367185 - [IR] Fix getPointerAlignment for CallBase

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 09:30:40 PDT 2019


This should probably be a max of the two sources.

Philip

On 7/27/19 11:17 PM, Hideto Ueno via llvm-commits wrote:
> Author: uenoku
> Date: Sat Jul 27 23:17:46 2019
> New Revision: 367185
>
> URL: http://llvm.org/viewvc/llvm-project?rev=367185&view=rev
> Log:
> [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
>
> Modified:
>      llvm/trunk/lib/IR/Value.cpp
>
> Modified: llvm/trunk/lib/IR/Value.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=367185&r1=367184&r2=367185&view=diff
> ==============================================================================
> --- llvm/trunk/lib/IR/Value.cpp (original)
> +++ llvm/trunk/lib/IR/Value.cpp Sat Jul 27 23:17:46 2019
> @@ -723,9 +723,11 @@ unsigned Value::getPointerAlignment(cons
>         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();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list