From 1359ed722752c16edbc4d9963f74f79968499867 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 13 Nov 2022 22:05:37 +0000 Subject: [PATCH] [VectorUtils] Skip interleave members with diff type and alloca sizes. Currently, codegen doesn't support cases where the type size doesn't match the alloc size. Skip them for now. Fixes #58722. (cherry picked from commit 758699c39984296f20a4dac44c6892065601c4cd) --- llvm/lib/Analysis/VectorUtils.cpp | 7 +- ...interleave-allocsize-not-equal-typesize.ll | 83 +++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/LoopVectorize/AArch64/interleave-allocsize-not-equal-typesize.ll diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index ac0a3571e049f2..d7e5b7a0ab35c5 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -1106,6 +1106,12 @@ void InterleavedAccessInfo::collectConstStrideAccesses( continue; Type *ElementTy = getLoadStoreType(&I); + // Currently, codegen doesn't support cases where the type size doesn't + // match the alloc size. Skip them for now. + uint64_t Size = DL.getTypeAllocSize(ElementTy); + if (Size * 8 != DL.getTypeSizeInBits(ElementTy)) + continue; + // We don't check wrapping here because we don't know yet if Ptr will be // part of a full group or a group with gaps. Checking wrapping for all // pointers (even those that end up in groups with no gaps) will be overly @@ -1117,7 +1123,6 @@ void InterleavedAccessInfo::collectConstStrideAccesses( /*Assume=*/true, /*ShouldCheckWrap=*/false); const SCEV *Scev = replaceSymbolicStrideSCEV(PSE, Strides, Ptr); - uint64_t Size = DL.getTypeAllocSize(ElementTy); AccessStrideInfo[&I] = StrideDescriptor(Stride, Scev, Size, getLoadStoreAlignment(&I)); } diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/interleave-allocsize-not-equal-typesize.ll b/llvm/test/Transforms/LoopVectorize/AArch64/interleave-allocsize-not-equal-typesize.ll new file mode 100644 index 00000000000000..ebd1fec445e2f9 --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/AArch64/interleave-allocsize-not-equal-typesize.ll @@ -0,0 +1,83 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=loop-vectorize -S %s | FileCheck %s + +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-unknown-linux-gnu" + +; Make sure LV does not crash when analyzing potential interleave groups with +; accesses where the typesize doesn't match to allocsize. +define void @pr58722_load_interleave_group(ptr %src, ptr %dst) { +; CHECK-LABEL: @pr58722_load_interleave_group( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[GEP_IV:%.*]] = getelementptr inbounds i64, ptr [[SRC:%.*]], i64 [[IV]] +; CHECK-NEXT: [[V1:%.*]] = load i32, ptr [[GEP_IV]], align 4 +; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, ptr [[GEP_IV]], i64 1 +; CHECK-NEXT: [[V2:%.*]] = load i24, ptr [[GEP]], align 4 +; CHECK-NEXT: [[V2_EXT:%.*]] = zext i24 [[V2]] to i32 +; CHECK-NEXT: [[SUM:%.*]] = add i32 [[V1]], [[V2_EXT]] +; CHECK-NEXT: [[GEP_DST:%.*]] = getelementptr inbounds i32, ptr [[DST:%.*]], i64 [[IV]] +; CHECK-NEXT: store i32 [[SUM]], ptr [[GEP_DST]], align 4 +; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[IV]], 10000 +; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + br label %loop + +loop: + %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ] + %gep.iv = getelementptr inbounds i64, ptr %src, i64 %iv + %v1 = load i32, ptr %gep.iv, align 4 + %gep = getelementptr inbounds i32, ptr %gep.iv, i64 1 + %v2 = load i24, ptr %gep, align 4 + %v2.ext = zext i24 %v2 to i32 + %sum = add i32 %v1, %v2.ext + %gep.dst = getelementptr inbounds i32, ptr %dst, i64 %iv + store i32 %sum, ptr %gep.dst + %iv.next = add i64 %iv, 1 + %cmp = icmp eq i64 %iv, 10000 + br i1 %cmp, label %exit, label %loop + +exit: + ret void +} + +define void @pr58722_store_interleave_group(ptr %src, ptr %dst) { +; CHECK-LABEL: @pr58722_store_interleave_group( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ] +; CHECK-NEXT: [[GEP_IV:%.*]] = getelementptr inbounds i64, ptr [[SRC:%.*]], i32 [[IV]] +; CHECK-NEXT: store i32 [[IV]], ptr [[GEP_IV]], align 4 +; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i64, ptr [[GEP_IV]], i64 1 +; CHECK-NEXT: [[TRUNC_IV:%.*]] = trunc i32 [[IV]] to i24 +; CHECK-NEXT: store i24 [[TRUNC_IV]], ptr [[GEP]], align 4 +; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 2 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[IV]], 10000 +; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]] +; CHECK: exit: +; CHECK-NEXT: ret void +; +entry: + br label %loop + +loop: + %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ] + %gep.iv = getelementptr inbounds i64, ptr %src, i32 %iv + store i32 %iv, ptr %gep.iv + %gep = getelementptr inbounds i64, ptr %gep.iv, i64 1 + %trunc.iv = trunc i32 %iv to i24 + store i24 %trunc.iv, ptr %gep + %iv.next = add i32 %iv, 2 + %cmp = icmp eq i32 %iv, 10000 + br i1 %cmp, label %exit, label %loop + +exit: + ret void +}