[llvm] r257261 - [TRE] Simplify code with range-based loops and std::find.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 01:03:42 PST 2016


On Mon, Jan 11, 2016 at 5:49 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Sat, Jan 9, 2016 at 9:35 AM, Benjamin Kramer via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: d0k
>> Date: Sat Jan  9 11:35:29 2016
>> New Revision: 257261
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=257261&view=rev
>> Log:
>> [TRE] Simplify code with range-based loops and std::find.
>>
>> No functional change intended.
>>
>> Modified:
>>     llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=257261&r1=257260&r2=257261&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
>> (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp Sat Jan
>> 9 11:35:29 2016
>> @@ -425,9 +425,7 @@ bool TailCallElim::runTRE(Function &F) {
>>    // with themselves.  Check to see if we did and clean up our mess if
>> so.  This
>>    // occurs when a function passes an argument straight through to its
>> tail
>>    // call.
>> -  for (unsigned i = 0, e = ArgumentPHIs.size(); i != e; ++i) {
>> -    PHINode *PN = ArgumentPHIs[i];
>> -
>> +  for (PHINode *PN : ArgumentPHIs) {
>>      // If the PHI Node is a dynamic constant, replace it with the value
>> it is.
>>      if (Value *PNV = SimplifyInstruction(PN,
>> F.getParent()->getDataLayout())) {
>>        PN->replaceAllUsesWith(PNV);
>> @@ -468,10 +466,7 @@ bool TailCallElim::CanMoveAboveCall(Inst
>>    // return value of the call, it must only use things that are defined
>> before
>>    // the call, or movable instructions between the call and the
>> instruction
>>    // itself.
>> -  for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
>> -    if (I->getOperand(i) == CI)
>> -      return false;
>> -  return true;
>> +  return std::find(I->op_begin(), I->op_end(), CI) == I->op_end();
>
>
> Alternatively, this ^ could be llvm::any_of(I->ops(), CI);  maybe?

any_of needs a predicate, and imho adding std::equal_to<User *>(CI)
just adds noise here. I'd definitely pick any_of if we had C++14
std::equal_to<>(CI) though.

>
>>
>>  }
>>
>>  /// Return true if the specified value is the same when the return would
>> exit
>>
>>
>> _______________________________________________
>> 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