[PATCH] D16774: AMDGPU: Stop pointlessly looking at users after a bad one is found

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 10:12:09 PST 2016


On Mon, Feb 1, 2016 at 9:51 AM, Matt Arsenault via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> arsenm created this revision.
> arsenm added a reviewer: tstellarAMD.
> arsenm added a subscriber: llvm-commits.
> Herald added a subscriber: arsenm.
>
> http://reviews.llvm.org/D16774
>
> Files:
>   lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
>
> Index: lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
> ===================================================================
> --- lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
> +++ lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
> @@ -402,7 +402,10 @@
>  static bool collectUsesWithPtrTypes(Value *Val, std::vector<Value*>
> &WorkList) {
>    bool Success = true;
>    for (User *User : Val->users()) {
> -    if(std::find(WorkList.begin(), WorkList.end(), User) !=
> WorkList.end())
> +    if (!Success)
> +      return false;
> +
> +    if (std::find(WorkList.begin(), WorkList.end(), User) !=
> WorkList.end())
>        continue;
>      if (CallInst *CI = dyn_cast<CallInst>(User)) {
>        // TODO: We might be able to handle some cases where the callee is a
> @@ -429,10 +432,10 @@
>        continue;
>
>      WorkList.push_back(User);
> -
> -    Success &= collectUsesWithPtrTypes(User, WorkList);
> +    Success = collectUsesWithPtrTypes(User, WorkList);
>

Why not just drop the Success variable entirely and return from here:

if (!collectUsesWithPtrTypes(...))
  return false

Or, possibly better yet:

return llvm::all_of(Val->users(), [&](User *User) {
  ...
  return collectUsesWithPtrTypes(User, WorkList);
});


>    }
> -  return Success;
> +
> +  return true;
>  }
>
>  void AMDGPUPromoteAlloca::visitAlloca(AllocaInst &I) {
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160201/6b5bd26e/attachment.html>


More information about the llvm-commits mailing list