Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4692,6 +4692,11 @@ !isAccessInterleaved(&I) && !isLegalGatherOrScatter(&I)) continue; + // If the loaded value is truncated, consider the truncated type. + if (isa(&I) && I.hasOneUse() && + (isa(*I.user_begin()) || isa(*I.user_begin()))) + T = (*I.user_begin())->getType(); + MinWidth = std::min(MinWidth, (unsigned)DL.getTypeSizeInBits(T->getScalarType())); MaxWidth = std::max(MaxWidth, Index: test/Transforms/LoopVectorize/SystemZ/maxVF_truncload.ll =================================================================== --- /dev/null +++ test/Transforms/LoopVectorize/SystemZ/maxVF_truncload.ll @@ -0,0 +1,26 @@ +; RUN: opt < %s -mtriple=s390x-unknown-linux -mcpu=z13 -o - -loop-vectorize \ +; RUN: -debug-only=loop-vectorize 2>&1 | FileCheck %s +; REQUIRES: asserts +; +; CHECK: LV: The Smallest and Widest types: 32 / 32 bits. +; CHECK: LV: Selecting VF: 4. + +define void @fun(i64 %n, i32 %v, i64* %ptr, i32* %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 + %addr1 = getelementptr inbounds i32, i32* %dst, i64 %i + store i32 %conv, i32* %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 +} +