[PATCH] D150851: [LoopVectorize] Vectorize select-cmp reduction pattern for increasing integer induction variable
Ramkumar Ramachandra via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 21 09:04:27 PDT 2023
artagnon added a comment.
Hi Mel,
I had the chance to try out your patch today, and it seems that it's really quite restricted in its scope. I tried it out on this simple C program:
#include <stdio.h>
int main() {
int src[20000] = {4, 5, 2};
int r = 331;
for (int i = 0; i < 20000; i++) {
if (src[i] > 3)
r = i;
}
printf("%d\n", r);
return 0;
}
Unfortunately, your patch failed to vectorize this simple case, because when you match `NonPhi` against a `PHINode`, it is blocked on a `trunc`:
for.body: ; preds = %entry, %for.body
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
%r.05 = phi i32 [ 331, %entry ], [ %spec.select, %for.body ]
%arrayidx = getelementptr inbounds [20000 x i32], ptr %src, i64 0, i64 %indvars.iv
%3 = load i32, ptr %arrayidx, align 4, !tbaa !6
%cmp1 = icmp sgt i32 %3, 3
%4 = trunc i64 %indvars.iv to i32 // blocked here
%spec.select = select i1 %cmp1, i32 %4, i32 %r.05
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond.not = icmp eq i64 %indvars.iv.next, 20000
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !llvm.loop !10
May I suggest using the logic outlined in `isInductionMinMaxPattern` in D152693 <https://reviews.llvm.org/D152693>?
Thanks.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150851/new/
https://reviews.llvm.org/D150851
More information about the llvm-commits
mailing list