[PATCH] D52685: [LoopVectorizer] Adjust heuristics for a truncated load
Ayal Zaks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 3 09:40:01 PDT 2018
Ayal added inline comments.
================
Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:4698
+ (isa<TruncInst>(*I.user_begin()) || isa<FPTruncInst>(*I.user_begin())))
+ T = (*I.user_begin())->getType();
+
----------------
Ayal wrote:
> Call `*I.user_begin()`, or rather `user_back()`, once instead of thrice?
> Checking `isa<LoadInst>` is somewhat redundant.
> Taking the smaller `T` helps reduce `MinWidth`, but may also reduce `MaxWidth`.
One way of affecting only MinWidth:
```
{
Type *TruncT = (*I.user_begin())->getType();
MinWidth = std::min(MinWidth,
(unsigned)DL.getTypeSizeInBits(TruncT->getScalarType()));
}
```
================
Comment at: test/Transforms/LoopVectorize/SystemZ/maxVF_truncload.ll:5
+;
+; CHECK: LV: The Smallest and Widest types: 32 / 32 bits.
+; CHECK: LV: Selecting VF: 4.
----------------
jonpa wrote:
> Ayal wrote:
> > `Smallest` type should indeed be 32 bits, but `Widest` should (remain) 64 bits; unless the type of the original load should be ignored?
> I am not sure I follow here - 'Smallest' was 32 even without this patch, but 'Widest' was 64, right?
Ahh, right. There are two distinct issues here:
# how are Smallest and Widest types computed?
# which of Smallest or Widest type is used for setting MaxVF?
For the second issue, as @hsaito pointed out, see https://reviews.llvm.org/D44523.
The first issue, e.g., expanding "64 / 64 bits" into "32 / 64 bits" in the following revised example where both load and store are 64 bits but compute is 32 bits, would benefit from your patch:
```
define void @fun(i64 %n, i32 %v, i64* %ptr, i64* %dst) {
entry:
br label %for.body
for.body:
%i = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
%addr = getelementptr inbounds i64, i64* %ptr, i64 %i
%l64 = load i64, i64* %addr
%conv = trunc i64 %l64 to i32
%add = add i32 %conv, %v
%sext = sext i32 %add to i64
%addr1 = getelementptr inbounds i64, i64* %dst, i64 %i
store i64 %sext, i64* %addr1
%iv.next = add nuw nsw i64 %i, 1
%cmp = icmp slt i64 %iv.next, %n
br i1 %cmp, label %for.body, label %for.end
for.end:
ret void
}
```
https://reviews.llvm.org/D52685
More information about the llvm-commits
mailing list