[llvm] 7451bf0 - [SLP] use std::distance/find to reduce code; NFC

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 14:39:27 PDT 2020


Looks like this is a SmallVector, so it has random access iterators if
I'm reading the right code - could you use subtraction instead of
std::distance? (std::distance tends to be more relevant in generic
code where an iterator might not support random access, so it can fall
back to iteration to compute the difference)

On Mon, Sep 21, 2020 at 1:23 PM Sanjay Patel via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
>
> Author: Sanjay Patel
> Date: 2020-09-21T16:22:55-04:00
> New Revision: 7451bf0b0b6d77e9c39408aeedfa3fa90107fe7a
>
> URL: https://github.com/llvm/llvm-project/commit/7451bf0b0b6d77e9c39408aeedfa3fa90107fe7a
> DIFF: https://github.com/llvm/llvm-project/commit/7451bf0b0b6d77e9c39408aeedfa3fa90107fe7a.diff
>
> LOG: [SLP] use std::distance/find to reduce code; NFC
>
> We were already using this code pattern right after
> the loop, so this makes it consistent.
>
> Added:
>
>
> Modified:
>     llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
> index a9fbc7b38a3e..5fad74090489 100644
> --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
> +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
> @@ -4147,19 +4147,12 @@ Value *BoUpSLP::gather(ArrayRef<Value *> VL) {
>        // Add to our 'need-to-extract' list.
>        if (TreeEntry *E = getTreeEntry(VL[i])) {
>          // Find which lane we need to extract.
> -        int FoundLane = -1;
> -        for (unsigned Lane = 0, LE = E->Scalars.size(); Lane != LE; ++Lane) {
> -          // Is this the lane of the scalar that we are looking for ?
> -          if (E->Scalars[Lane] == VL[i]) {
> -            FoundLane = Lane;
> -            break;
> -          }
> -        }
> -        assert(FoundLane >= 0 && "Could not find the correct lane");
> +        unsigned FoundLane =
> +            std::distance(E->Scalars.begin(), find(E->Scalars, VL[i]));
> +        assert(FoundLane < E->Scalars.size() && "Could not find extract lane");
>          if (!E->ReuseShuffleIndices.empty()) {
> -          FoundLane =
> -              std::distance(E->ReuseShuffleIndices.begin(),
> -                            llvm::find(E->ReuseShuffleIndices, FoundLane));
> +          FoundLane = std::distance(E->ReuseShuffleIndices.begin(),
> +                                    find(E->ReuseShuffleIndices, FoundLane));
>          }
>          ExternalUses.push_back(ExternalUser(VL[i], Insrt, FoundLane));
>        }
>
>
>
> _______________________________________________
> 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