Skip to content

Commit b09f359

Browse files
committed
Fixups
1 parent ac07996 commit b09f359

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

llvm/include/llvm/IR/VectorTypeUtils.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ inline bool isVectorizedTy(Type *Ty) {
7575
return Ty->isVectorTy();
7676
}
7777

78-
// Returns true if `Ty` is a valid vector element type, void, or an unpacked
79-
// literal struct where all elements are valid vector element types.
80-
// Note: Even if a type can be vectorized that does not mean it is valid to do
81-
// so in all cases. For example, a vectorized struct (as returned by
82-
// toVectorizedTy) does not perform (de)interleaving, so it can't be used for
83-
// vectorizing loads/stores.
78+
/// Returns true if `Ty` is a valid vector element type, void, or an unpacked
79+
/// literal struct where all elements are valid vector element types.
80+
/// Note: Even if a type can be vectorized that does not mean it is valid to do
81+
/// so in all cases. For example, a vectorized struct (as returned by
82+
/// toVectorizedTy) does not perform (de)interleaving, so it can't be used for
83+
/// vectorizing loads/stores.
8484
inline bool canVectorizeTy(Type *Ty) {
8585
if (StructType *StructTy = dyn_cast<StructType>(Ty))
8686
return canVectorizeStructTy(StructTy);

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,12 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
958958
Type *InstTy = Inst.getType();
959959
if (isa<CallInst>(Inst) && isa<StructType>(InstTy) &&
960960
canWidenCallReturnType(InstTy)) {
961+
// TODO: Remove the `StructVecCallFound` flag once vectorizing calls
962+
// with struct returns is supported.
961963
StructVecCallFound = true;
962-
// For now, we can only widen struct values returned from calls where
963-
// all users are extractvalue instructions.
964-
return llvm::all_of(Inst.users(), IsaPred<ExtractValueInst>);
964+
// For now, we only recognize struct values returned from calls where
965+
// all users are extractvalue as vectorizable.
966+
return all_of(Inst.users(), IsaPred<ExtractValueInst>);
965967
}
966968
return VectorType::isValidElementType(InstTy) || InstTy->isVoidTy();
967969
};

llvm/test/Transforms/LoopVectorize/struct-return.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,33 @@ exit:
167167
ret void
168168
}
169169

170+
; Negative test. Widening structs of vectors is not supported.
171+
; CHECK-REMARKS-COUNT: remark: {{.*}} loop not vectorized: instruction return type cannot be vectorized
172+
define void @negative_struct_of_vectors(ptr noalias %in, ptr noalias writeonly %out_a, ptr noalias writeonly %out_b) {
173+
; CHECK-LABEL: define void @negative_struct_of_vectors
174+
; CHECK-NOT: vector.body:
175+
entry:
176+
br label %for.body
177+
178+
for.body:
179+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
180+
%arrayidx = getelementptr inbounds float, ptr %in, i64 %iv
181+
%in_val = load <1 x float>, ptr %arrayidx, align 4
182+
%call = tail call { <1 x float>, <1 x float> } @foo(<1 x float> %in_val) #0
183+
%extract_a = extractvalue { <1 x float>, <1 x float> } %call, 0
184+
%extract_b = extractvalue { <1 x float>, <1 x float> } %call, 1
185+
%arrayidx2 = getelementptr inbounds float, ptr %out_a, i64 %iv
186+
store <1 x float> %extract_a, ptr %arrayidx2, align 4
187+
%arrayidx4 = getelementptr inbounds float, ptr %out_b, i64 %iv
188+
store <1 x float> %extract_b, ptr %arrayidx4, align 4
189+
%iv.next = add nuw nsw i64 %iv, 1
190+
%exitcond.not = icmp eq i64 %iv.next, 1024
191+
br i1 %exitcond.not, label %exit, label %for.body
192+
193+
exit:
194+
ret void
195+
}
196+
170197
; Negative test. Widening structs with mixed element types is not supported.
171198
; CHECK-REMARKS-COUNT: remark: {{.*}} loop not vectorized: instruction return type cannot be vectorized
172199
define void @negative_mixed_element_type_struct_return(ptr noalias %in, ptr noalias writeonly %out_a, ptr noalias writeonly %out_b) {
@@ -361,6 +388,7 @@ declare %named_struct @bar_named(double)
361388
declare { { float, float } } @foo_nested_struct(float)
362389
declare { [2 x float] } @foo_arrays(float)
363390
declare { float, [1 x float] } @foo_one_non_widenable_element(float)
391+
declare { <1 x float>, <1 x float> } @foo_vectors(<1 x float>)
364392
declare { i32, i32, i32 } @qux(i32)
365393

366394
declare { <2 x float>, <2 x float> } @fixed_vec_foo(<2 x float>)

0 commit comments

Comments
 (0)