blob: 41ce063c9ca4eab332304b95d25abff498717352 [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
; RUN: opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-target-instruction-cost=1 -S | FileCheck %s --check-prefixes=WIDE
; RUN: opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-target-instruction-cost=1 -vectorizer-maximize-bandwidth-for-vector-calls=false -S | FileCheck %s --check-prefixes=NARROW
define void @test_widen(ptr noalias %a, ptr readnone %b) {
; WIDE-LABEL: define void @test_widen(
; WIDE-SAME: ptr noalias [[A:%.*]], ptr readnone [[B:%.*]]) {
; WIDE-NEXT: [[ENTRY:.*:]]
; WIDE-NEXT: br label %[[VECTOR_PH:.*]]
; WIDE: [[VECTOR_PH]]:
; WIDE-NEXT: br label %[[VECTOR_BODY:.*]]
; WIDE: [[VECTOR_BODY]]:
; WIDE-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; WIDE-NEXT: [[TMP0:%.*]] = getelementptr i16, ptr [[B]], i64 [[INDEX]]
; WIDE-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i16>, ptr [[TMP0]], align 2
; WIDE-NEXT: [[TMP1:%.*]] = trunc <4 x i16> [[WIDE_LOAD]] to <4 x i8>
; WIDE-NEXT: [[TMP2:%.*]] = call <4 x i8> @foo_vector(<4 x i8> [[TMP1]])
; WIDE-NEXT: [[TMP3:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[INDEX]]
; WIDE-NEXT: store <4 x i8> [[TMP2]], ptr [[TMP3]], align 1
; WIDE-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
; WIDE-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
; WIDE-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
; WIDE: [[MIDDLE_BLOCK]]:
; WIDE-NEXT: br label %[[SCALAR_PH:.*]]
; WIDE: [[SCALAR_PH]]:
; WIDE-NEXT: br label %[[FOR_BODY:.*]]
; WIDE: [[FOR_BODY]]:
; WIDE-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 1024, %[[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
; WIDE-NEXT: [[GEP:%.*]] = getelementptr i16, ptr [[B]], i64 [[INDVARS_IV]]
; WIDE-NEXT: [[LOAD:%.*]] = load i16, ptr [[GEP]], align 2
; WIDE-NEXT: [[TRUNC:%.*]] = trunc i16 [[LOAD]] to i8
; WIDE-NEXT: [[CALL:%.*]] = call i8 @foo(i8 [[TRUNC]]) #[[ATTR0:[0-9]+]]
; WIDE-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[INDVARS_IV]]
; WIDE-NEXT: store i8 [[CALL]], ptr [[ARRAYIDX]], align 1
; WIDE-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
; WIDE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 1025
; WIDE-NEXT: br i1 [[EXITCOND]], label %[[FOR_COND_CLEANUP:.*]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
; WIDE: [[FOR_COND_CLEANUP]]:
; WIDE-NEXT: ret void
;
; NARROW-LABEL: define void @test_widen(
; NARROW-SAME: ptr noalias [[A:%.*]], ptr readnone [[B:%.*]]) {
; NARROW-NEXT: [[ENTRY:.*:]]
; NARROW-NEXT: br label %[[VECTOR_PH:.*]]
; NARROW: [[VECTOR_PH]]:
; NARROW-NEXT: br label %[[VECTOR_BODY:.*]]
; NARROW: [[VECTOR_BODY]]:
; NARROW-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; NARROW-NEXT: [[TMP0:%.*]] = getelementptr i16, ptr [[B]], i64 [[INDEX]]
; NARROW-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i16>, ptr [[TMP0]], align 2
; NARROW-NEXT: [[TMP1:%.*]] = trunc <2 x i16> [[WIDE_LOAD]] to <2 x i8>
; NARROW-NEXT: [[TMP2:%.*]] = extractelement <2 x i8> [[TMP1]], i64 0
; NARROW-NEXT: [[TMP3:%.*]] = call i8 @foo(i8 [[TMP2]]) #[[ATTR0:[0-9]+]]
; NARROW-NEXT: [[TMP4:%.*]] = extractelement <2 x i8> [[TMP1]], i64 1
; NARROW-NEXT: [[TMP5:%.*]] = call i8 @foo(i8 [[TMP4]]) #[[ATTR0]]
; NARROW-NEXT: [[TMP6:%.*]] = insertelement <2 x i8> poison, i8 [[TMP3]], i64 0
; NARROW-NEXT: [[TMP7:%.*]] = insertelement <2 x i8> [[TMP6]], i8 [[TMP5]], i64 1
; NARROW-NEXT: [[TMP8:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[INDEX]]
; NARROW-NEXT: store <2 x i8> [[TMP7]], ptr [[TMP8]], align 1
; NARROW-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
; NARROW-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
; NARROW-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
; NARROW: [[MIDDLE_BLOCK]]:
; NARROW-NEXT: br label %[[SCALAR_PH:.*]]
; NARROW: [[SCALAR_PH]]:
; NARROW-NEXT: br label %[[FOR_BODY:.*]]
; NARROW: [[FOR_BODY]]:
; NARROW-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 1024, %[[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY]] ]
; NARROW-NEXT: [[GEP:%.*]] = getelementptr i16, ptr [[B]], i64 [[INDVARS_IV]]
; NARROW-NEXT: [[LOAD:%.*]] = load i16, ptr [[GEP]], align 2
; NARROW-NEXT: [[TRUNC:%.*]] = trunc i16 [[LOAD]] to i8
; NARROW-NEXT: [[CALL:%.*]] = call i8 @foo(i8 [[TRUNC]]) #[[ATTR0]]
; NARROW-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[INDVARS_IV]]
; NARROW-NEXT: store i8 [[CALL]], ptr [[ARRAYIDX]], align 1
; NARROW-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
; NARROW-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 1025
; NARROW-NEXT: br i1 [[EXITCOND]], label %[[FOR_COND_CLEANUP:.*]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
; NARROW: [[FOR_COND_CLEANUP]]:
; NARROW-NEXT: ret void
;
entry:
br label %for.body
for.body:
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
%gep = getelementptr i16, ptr %b, i64 %indvars.iv
%load = load i16, ptr %gep
%trunc = trunc i16 %load to i8
%call = call i8 @foo(i8 %trunc) #0
%arrayidx = getelementptr inbounds i8, ptr %a, i64 %indvars.iv
store i8 %call, ptr %arrayidx
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond = icmp eq i64 %indvars.iv.next, 1025
br i1 %exitcond, label %for.cond.cleanup, label %for.body
for.cond.cleanup:
ret void
}
declare i8 @foo(i8)
declare <4 x i8> @foo_vector(<4 x i8>)
attributes #0 = { nounwind "vector-function-abi-variant"="_ZGV_LLVM_N4v_foo(foo_vector)" }