[llvm] r290905 - [CodeGen] Simplify logic that looks for returned call operands. NFC-ish.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 12:47:03 PST 2017


> On Jan 3, 2017, at 12:33 PM, Ahmed Bougacha via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: ab
> Date: Tue Jan  3 14:33:22 2017
> New Revision: 290905
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=290905&view=rev
> Log:
> [CodeGen] Simplify logic that looks for returned call operands. NFC-ish.
> 
> Use getReturnedArgOperand() instead of rolling our own.  Note that it's
> equivalent because there can only be one 'returned' operand.
> 
> The existing code was also incorrect: there already was awkward logic to
> ignore callee/EH blocks, but operands can now also be operand bundles,
> in which case we'll look for non-existent parameter attributes.
> 
> Unfortunately, this isn't observable in-tree, as it only crashes when
> exercising the regular call lowering logic with operand bundles.
> Still, this is a nice small cleanup anyway.
> 
> Modified:
>    llvm/trunk/lib/CodeGen/Analysis.cpp
> 
> Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=290905&r1=290904&r2=290905&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
> +++ llvm/trunk/lib/CodeGen/Analysis.cpp Tue Jan  3 14:33:22 2017
> @@ -272,28 +272,16 @@ static const Value *getNoopInput(const V
>                TLI.allowTruncateForTailCall(Op->getType(), I->getType())) {
>       DataBits = std::min(DataBits, I->getType()->getPrimitiveSizeInBits());
>       NoopInput = Op;
> -    } else if (isa<CallInst>(I)) {
> -      // Look through call (skipping callee)
> -      for (User::const_op_iterator i = I->op_begin(), e = I->op_end() - 1;
> -           i != e; ++i) {
> -        unsigned attrInd = i - I->op_begin() + 1;
> -        if (cast<CallInst>(I)->paramHasAttr(attrInd, Attribute::Returned) &&
> -            isNoopBitcast((*i)->getType(), I->getType(), TLI)) {
> -          NoopInput = *i;
> -          break;
> -        }
> -      }
> -    } else if (isa<InvokeInst>(I)) {
> -      // Look through invoke (skipping BB, BB, Callee)
> -      for (User::const_op_iterator i = I->op_begin(), e = I->op_end() - 3;
> -           i != e; ++i) {
> -        unsigned attrInd = i - I->op_begin() + 1;
> -        if (cast<InvokeInst>(I)->paramHasAttr(attrInd, Attribute::Returned) &&
> -            isNoopBitcast((*i)->getType(), I->getType(), TLI)) {
> -          NoopInput = *i;
> -          break;
> -        }
> -      }
> +    } else if (auto *CI = dyn_cast<CallInst>(I)) {
> +      // Look through call operands.
> +      Value *ReturnedOp = CI->getReturnedArgOperand();
> +      if (ReturnedOp && isNoopBitcast(ReturnedOp->getType(), I->getType(), TLI))
> +        NoopInput = ReturnedOp;
> +    } else if (auto *II = dyn_cast<InvokeInst>(I)) {
> +      // Look through invoke operands.
> +      Value *ReturnedOp = II->getReturnedArgOperand();
> +      if (ReturnedOp && isNoopBitcast(ReturnedOp->getType(), I->getType(), TLI))
> +        NoopInput = ReturnedOp;
Can this all be folded in to a single conditional using CallSite?

Cheers,
Pete
>     } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(V)) {
>       // Value may come from either the aggregate or the scalar
>       ArrayRef<unsigned> InsertLoc = IVI->getIndices();
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list