diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3690,6 +3690,9 @@ TTI->getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy, None, 0); } + // No cost for "gathering" already vector value + if (isa(VL[0])) + return 0; if (E->getOpcode() == Instruction::ExtractElement && allSameType(VL) && allSameBlock(VL)) { SmallVector Mask; @@ -4591,6 +4594,18 @@ Value *BoUpSLP::gather(ArrayRef VL) { Value *Val0 = isa(VL[0]) ? cast(VL[0])->getValueOperand() : VL[0]; + + // "Gathering" of vector values is already done, + // just return the last insert instruction. + if (isa(Val0)) { + for (auto *I : VL) + if (llvm::all_of(VL, [I](Value *V) { + return cast(V)->getOperand(0) != I; + })) + return I; + llvm_unreachable("No last insert"); + } + FixedVectorType *VecTy = FixedVectorType::get(Val0->getType(), VL.size()); Value *Vec = PoisonValue::get(VecTy); unsigned InsIndex = 0; diff --git a/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-inseltpoison.ll b/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-inseltpoison.ll --- a/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-inseltpoison.ll +++ b/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-inseltpoison.ll @@ -1,6 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 < %s | FileCheck %s -; RUN: opt -S -slp-vectorizer -slp-threshold=0 < %s | FileCheck %s +; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 < %s | FileCheck %s --check-prefixes=CHECK,THRESHOLD +; RUN: opt -S -slp-vectorizer -slp-threshold=0 < %s | FileCheck %s --check-prefixes=CHECK,NOTHRESHOLD +; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 -slp-min-tree-size=0 < %s | FileCheck %s --check-prefixes=CHECK,MINTREESIZE target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.8.0" @@ -42,41 +43,119 @@ ; This entire tree is ephemeral, don't vectorize any of it. define <4 x float> @simple_select_eph(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 { -; CHECK-LABEL: @simple_select_eph( -; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 -; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 -; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 -; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 -; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 -; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 -; CHECK-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 -; CHECK-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 -; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 -; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 -; CHECK-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 -; CHECK-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 -; CHECK-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 -; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 -; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 -; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 -; CHECK-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] -; CHECK-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] -; CHECK-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] -; CHECK-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] -; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0 -; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 -; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 -; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 -; CHECK-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 -; CHECK-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 -; CHECK-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 -; CHECK-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 -; CHECK-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] -; CHECK-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] -; CHECK-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] -; CHECK-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] -; CHECK-NEXT: call void @llvm.assume(i1 [[QI]]) -; CHECK-NEXT: ret <4 x float> undef +; THRESHOLD-LABEL: @simple_select_eph( +; THRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 +; THRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 +; THRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 +; THRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 +; THRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 +; THRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 +; THRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 +; THRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 +; THRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 +; THRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 +; THRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; THRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 +; THRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 +; THRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 +; THRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 +; THRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 +; THRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] +; THRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] +; THRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] +; THRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] +; THRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0 +; THRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 +; THRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 +; THRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 +; THRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 +; THRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 +; THRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 +; THRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 +; THRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] +; THRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] +; THRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] +; THRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] +; THRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]]) +; THRESHOLD-NEXT: ret <4 x float> undef +; +; NOTHRESHOLD-LABEL: @simple_select_eph( +; NOTHRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 +; NOTHRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 +; NOTHRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 +; NOTHRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 +; NOTHRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 +; NOTHRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 +; NOTHRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 +; NOTHRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 +; NOTHRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 +; NOTHRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 +; NOTHRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; NOTHRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 +; NOTHRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 +; NOTHRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 +; NOTHRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 +; NOTHRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 +; NOTHRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] +; NOTHRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] +; NOTHRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] +; NOTHRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] +; NOTHRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0 +; NOTHRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 +; NOTHRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 +; NOTHRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 +; NOTHRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 +; NOTHRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 +; NOTHRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 +; NOTHRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 +; NOTHRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] +; NOTHRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] +; NOTHRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] +; NOTHRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] +; NOTHRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]]) +; NOTHRESHOLD-NEXT: ret <4 x float> undef +; +; MINTREESIZE-LABEL: @simple_select_eph( +; MINTREESIZE-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 +; MINTREESIZE-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 +; MINTREESIZE-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 +; MINTREESIZE-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 +; MINTREESIZE-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 +; MINTREESIZE-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 +; MINTREESIZE-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 +; MINTREESIZE-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 +; MINTREESIZE-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 +; MINTREESIZE-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 +; MINTREESIZE-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 +; MINTREESIZE-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 +; MINTREESIZE-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] +; MINTREESIZE-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] +; MINTREESIZE-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] +; MINTREESIZE-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] +; MINTREESIZE-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0 +; MINTREESIZE-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 +; MINTREESIZE-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 +; MINTREESIZE-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 +; MINTREESIZE-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 +; MINTREESIZE-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 +; MINTREESIZE-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 +; MINTREESIZE-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 +; MINTREESIZE-NEXT: [[TMP1:%.*]] = insertelement <2 x float> poison, float [[Q2]], i32 0 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = insertelement <2 x float> [[TMP1]], float [[Q3]], i32 1 +; MINTREESIZE-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] +; MINTREESIZE-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] +; MINTREESIZE-NEXT: [[TMP3:%.*]] = insertelement <2 x float> poison, float [[Q4]], i32 0 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = insertelement <2 x float> [[TMP3]], float [[Q5]], i32 1 +; MINTREESIZE-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] +; MINTREESIZE-NEXT: [[TMP5:%.*]] = insertelement <2 x float> poison, float [[Q6]], i32 0 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = insertelement <2 x float> [[TMP5]], float [[Q5]], i32 1 +; MINTREESIZE-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] +; MINTREESIZE-NEXT: call void @llvm.assume(i1 [[QI]]) +; MINTREESIZE-NEXT: ret <4 x float> undef ; %c0 = extractelement <4 x i32> %c, i32 0 %c1 = extractelement <4 x i32> %c, i32 1 @@ -350,9 +429,33 @@ ; Make sure that vectorization happens even if insertelements operations ; must be rescheduled. The case here is from compiling Julia. define <4 x float> @reschedule_extract(<4 x float> %a, <4 x float> %b) { -; CHECK-LABEL: @reschedule_extract( -; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: ret <4 x float> [[TMP1]] +; THRESHOLD-LABEL: @reschedule_extract( +; THRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; THRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; NOTHRESHOLD-LABEL: @reschedule_extract( +; NOTHRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; NOTHRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; MINTREESIZE-LABEL: @reschedule_extract( +; MINTREESIZE-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[B:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[B]], i32 0 +; MINTREESIZE-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[A:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[TMP7:%.*]] = extractelement <4 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[TMP8:%.*]] = extractelement <4 x float> [[A]], i32 0 +; MINTREESIZE-NEXT: [[TMP9:%.*]] = insertelement <2 x float> poison, float [[TMP8]], i32 0 +; MINTREESIZE-NEXT: [[TMP10:%.*]] = insertelement <2 x float> [[TMP9]], float [[TMP4]], i32 1 +; MINTREESIZE-NEXT: [[TMP11:%.*]] = insertelement <2 x float> poison, float [[TMP7]], i32 0 +; MINTREESIZE-NEXT: [[TMP12:%.*]] = insertelement <2 x float> [[TMP11]], float [[TMP3]], i32 1 +; MINTREESIZE-NEXT: [[TMP13:%.*]] = insertelement <2 x float> poison, float [[TMP6]], i32 0 +; MINTREESIZE-NEXT: [[TMP14:%.*]] = insertelement <2 x float> [[TMP13]], float [[TMP2]], i32 1 +; MINTREESIZE-NEXT: [[TMP15:%.*]] = insertelement <2 x float> poison, float [[TMP5]], i32 0 +; MINTREESIZE-NEXT: [[TMP16:%.*]] = insertelement <2 x float> [[TMP15]], float [[TMP1]], i32 1 +; MINTREESIZE-NEXT: [[TMP17:%.*]] = fadd <4 x float> [[A]], [[B]] +; MINTREESIZE-NEXT: ret <4 x float> [[TMP17]] ; %a0 = extractelement <4 x float> %a, i32 0 %b0 = extractelement <4 x float> %b, i32 0 @@ -376,9 +479,33 @@ ; Check that cost model for vectorization takes credit for ; instructions that are erased. define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) { -; CHECK-LABEL: @take_credit( -; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: ret <4 x float> [[TMP1]] +; THRESHOLD-LABEL: @take_credit( +; THRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; THRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; NOTHRESHOLD-LABEL: @take_credit( +; NOTHRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; NOTHRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; MINTREESIZE-LABEL: @take_credit( +; MINTREESIZE-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[B:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[B]], i32 0 +; MINTREESIZE-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[A:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[TMP7:%.*]] = extractelement <4 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[TMP8:%.*]] = extractelement <4 x float> [[A]], i32 0 +; MINTREESIZE-NEXT: [[TMP9:%.*]] = insertelement <2 x float> poison, float [[TMP8]], i32 0 +; MINTREESIZE-NEXT: [[TMP10:%.*]] = insertelement <2 x float> [[TMP9]], float [[TMP4]], i32 1 +; MINTREESIZE-NEXT: [[TMP11:%.*]] = insertelement <2 x float> poison, float [[TMP7]], i32 0 +; MINTREESIZE-NEXT: [[TMP12:%.*]] = insertelement <2 x float> [[TMP11]], float [[TMP3]], i32 1 +; MINTREESIZE-NEXT: [[TMP13:%.*]] = insertelement <2 x float> poison, float [[TMP6]], i32 0 +; MINTREESIZE-NEXT: [[TMP14:%.*]] = insertelement <2 x float> [[TMP13]], float [[TMP2]], i32 1 +; MINTREESIZE-NEXT: [[TMP15:%.*]] = insertelement <2 x float> poison, float [[TMP5]], i32 0 +; MINTREESIZE-NEXT: [[TMP16:%.*]] = insertelement <2 x float> [[TMP15]], float [[TMP1]], i32 1 +; MINTREESIZE-NEXT: [[TMP17:%.*]] = fadd <4 x float> [[A]], [[B]] +; MINTREESIZE-NEXT: ret <4 x float> [[TMP17]] ; %a0 = extractelement <4 x float> %a, i32 0 %b0 = extractelement <4 x float> %b, i32 0 @@ -426,9 +553,49 @@ } define <8 x float> @_vadd256(<8 x float> %a, <8 x float> %b) local_unnamed_addr #0 { -; CHECK-LABEL: @_vadd256( -; CHECK-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: ret <8 x float> [[TMP1]] +; THRESHOLD-LABEL: @_vadd256( +; THRESHOLD-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]] +; THRESHOLD-NEXT: ret <8 x float> [[TMP1]] +; +; NOTHRESHOLD-LABEL: @_vadd256( +; NOTHRESHOLD-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]] +; NOTHRESHOLD-NEXT: ret <8 x float> [[TMP1]] +; +; MINTREESIZE-LABEL: @_vadd256( +; MINTREESIZE-NEXT: [[TMP1:%.*]] = extractelement <8 x float> [[B:%.*]], i32 7 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = extractelement <8 x float> [[B]], i32 6 +; MINTREESIZE-NEXT: [[TMP3:%.*]] = extractelement <8 x float> [[B]], i32 5 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = extractelement <8 x float> [[B]], i32 4 +; MINTREESIZE-NEXT: [[TMP5:%.*]] = extractelement <8 x float> [[B]], i32 3 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = extractelement <8 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[TMP7:%.*]] = extractelement <8 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[TMP8:%.*]] = extractelement <8 x float> [[B]], i32 0 +; MINTREESIZE-NEXT: [[TMP9:%.*]] = extractelement <8 x float> [[A:%.*]], i32 7 +; MINTREESIZE-NEXT: [[TMP10:%.*]] = extractelement <8 x float> [[A]], i32 6 +; MINTREESIZE-NEXT: [[TMP11:%.*]] = extractelement <8 x float> [[A]], i32 5 +; MINTREESIZE-NEXT: [[TMP12:%.*]] = extractelement <8 x float> [[A]], i32 4 +; MINTREESIZE-NEXT: [[TMP13:%.*]] = extractelement <8 x float> [[A]], i32 3 +; MINTREESIZE-NEXT: [[TMP14:%.*]] = extractelement <8 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[TMP15:%.*]] = extractelement <8 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[TMP16:%.*]] = extractelement <8 x float> [[A]], i32 0 +; MINTREESIZE-NEXT: [[TMP17:%.*]] = insertelement <2 x float> poison, float [[TMP16]], i32 0 +; MINTREESIZE-NEXT: [[TMP18:%.*]] = insertelement <2 x float> [[TMP17]], float [[TMP8]], i32 1 +; MINTREESIZE-NEXT: [[TMP19:%.*]] = insertelement <2 x float> poison, float [[TMP15]], i32 0 +; MINTREESIZE-NEXT: [[TMP20:%.*]] = insertelement <2 x float> [[TMP19]], float [[TMP7]], i32 1 +; MINTREESIZE-NEXT: [[TMP21:%.*]] = insertelement <2 x float> poison, float [[TMP14]], i32 0 +; MINTREESIZE-NEXT: [[TMP22:%.*]] = insertelement <2 x float> [[TMP21]], float [[TMP6]], i32 1 +; MINTREESIZE-NEXT: [[TMP23:%.*]] = insertelement <2 x float> poison, float [[TMP13]], i32 0 +; MINTREESIZE-NEXT: [[TMP24:%.*]] = insertelement <2 x float> [[TMP23]], float [[TMP5]], i32 1 +; MINTREESIZE-NEXT: [[TMP25:%.*]] = insertelement <2 x float> poison, float [[TMP12]], i32 0 +; MINTREESIZE-NEXT: [[TMP26:%.*]] = insertelement <2 x float> [[TMP25]], float [[TMP4]], i32 1 +; MINTREESIZE-NEXT: [[TMP27:%.*]] = insertelement <2 x float> poison, float [[TMP11]], i32 0 +; MINTREESIZE-NEXT: [[TMP28:%.*]] = insertelement <2 x float> [[TMP27]], float [[TMP3]], i32 1 +; MINTREESIZE-NEXT: [[TMP29:%.*]] = insertelement <2 x float> poison, float [[TMP10]], i32 0 +; MINTREESIZE-NEXT: [[TMP30:%.*]] = insertelement <2 x float> [[TMP29]], float [[TMP2]], i32 1 +; MINTREESIZE-NEXT: [[TMP31:%.*]] = insertelement <2 x float> poison, float [[TMP9]], i32 0 +; MINTREESIZE-NEXT: [[TMP32:%.*]] = insertelement <2 x float> [[TMP31]], float [[TMP1]], i32 1 +; MINTREESIZE-NEXT: [[TMP33:%.*]] = fadd <8 x float> [[A]], [[B]] +; MINTREESIZE-NEXT: ret <8 x float> [[TMP33]] ; %vecext = extractelement <8 x float> %a, i32 0 %vecext1 = extractelement <8 x float> %b, i32 0 diff --git a/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector.ll b/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector.ll --- a/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector.ll +++ b/llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector.ll @@ -1,6 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 < %s | FileCheck %s -; RUN: opt -S -slp-vectorizer -slp-threshold=0 < %s | FileCheck %s +; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 < %s | FileCheck %s --check-prefixes=CHECK,THRESHOLD +; RUN: opt -S -slp-vectorizer -slp-threshold=0 < %s | FileCheck %s --check-prefixes=CHECK,NOTHRESHOLD +; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 -slp-min-tree-size=0 < %s | FileCheck %s --check-prefixes=CHECK,MINTREESIZE target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.8.0" @@ -42,41 +43,119 @@ ; This entire tree is ephemeral, don't vectorize any of it. define <4 x float> @simple_select_eph(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 { -; CHECK-LABEL: @simple_select_eph( -; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 -; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 -; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 -; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 -; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 -; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 -; CHECK-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 -; CHECK-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 -; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 -; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 -; CHECK-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 -; CHECK-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 -; CHECK-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 -; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 -; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 -; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 -; CHECK-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] -; CHECK-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] -; CHECK-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] -; CHECK-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] -; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0 -; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 -; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 -; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 -; CHECK-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 -; CHECK-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 -; CHECK-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 -; CHECK-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 -; CHECK-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] -; CHECK-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] -; CHECK-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] -; CHECK-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] -; CHECK-NEXT: call void @llvm.assume(i1 [[QI]]) -; CHECK-NEXT: ret <4 x float> undef +; THRESHOLD-LABEL: @simple_select_eph( +; THRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 +; THRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 +; THRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 +; THRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 +; THRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 +; THRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 +; THRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 +; THRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 +; THRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 +; THRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 +; THRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; THRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 +; THRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 +; THRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 +; THRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 +; THRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 +; THRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] +; THRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] +; THRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] +; THRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] +; THRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0 +; THRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 +; THRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 +; THRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 +; THRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 +; THRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 +; THRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 +; THRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 +; THRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] +; THRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] +; THRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] +; THRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] +; THRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]]) +; THRESHOLD-NEXT: ret <4 x float> undef +; +; NOTHRESHOLD-LABEL: @simple_select_eph( +; NOTHRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 +; NOTHRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 +; NOTHRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 +; NOTHRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 +; NOTHRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 +; NOTHRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 +; NOTHRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 +; NOTHRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 +; NOTHRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 +; NOTHRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 +; NOTHRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; NOTHRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 +; NOTHRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 +; NOTHRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 +; NOTHRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 +; NOTHRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 +; NOTHRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] +; NOTHRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] +; NOTHRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] +; NOTHRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] +; NOTHRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0 +; NOTHRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 +; NOTHRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 +; NOTHRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 +; NOTHRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 +; NOTHRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 +; NOTHRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 +; NOTHRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 +; NOTHRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] +; NOTHRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] +; NOTHRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] +; NOTHRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] +; NOTHRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]]) +; NOTHRESHOLD-NEXT: ret <4 x float> undef +; +; MINTREESIZE-LABEL: @simple_select_eph( +; MINTREESIZE-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0 +; MINTREESIZE-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1 +; MINTREESIZE-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2 +; MINTREESIZE-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3 +; MINTREESIZE-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0 +; MINTREESIZE-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3 +; MINTREESIZE-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0 +; MINTREESIZE-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3 +; MINTREESIZE-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0 +; MINTREESIZE-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0 +; MINTREESIZE-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0 +; MINTREESIZE-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0 +; MINTREESIZE-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]] +; MINTREESIZE-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]] +; MINTREESIZE-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]] +; MINTREESIZE-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]] +; MINTREESIZE-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0 +; MINTREESIZE-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1 +; MINTREESIZE-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2 +; MINTREESIZE-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3 +; MINTREESIZE-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0 +; MINTREESIZE-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1 +; MINTREESIZE-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2 +; MINTREESIZE-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3 +; MINTREESIZE-NEXT: [[TMP1:%.*]] = insertelement <2 x float> poison, float [[Q2]], i32 0 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = insertelement <2 x float> [[TMP1]], float [[Q3]], i32 1 +; MINTREESIZE-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]] +; MINTREESIZE-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]] +; MINTREESIZE-NEXT: [[TMP3:%.*]] = insertelement <2 x float> poison, float [[Q4]], i32 0 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = insertelement <2 x float> [[TMP3]], float [[Q5]], i32 1 +; MINTREESIZE-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]] +; MINTREESIZE-NEXT: [[TMP5:%.*]] = insertelement <2 x float> poison, float [[Q6]], i32 0 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = insertelement <2 x float> [[TMP5]], float [[Q5]], i32 1 +; MINTREESIZE-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]] +; MINTREESIZE-NEXT: call void @llvm.assume(i1 [[QI]]) +; MINTREESIZE-NEXT: ret <4 x float> undef ; %c0 = extractelement <4 x i32> %c, i32 0 %c1 = extractelement <4 x i32> %c, i32 1 @@ -350,9 +429,33 @@ ; Make sure that vectorization happens even if insertelements operations ; must be rescheduled. The case here is from compiling Julia. define <4 x float> @reschedule_extract(<4 x float> %a, <4 x float> %b) { -; CHECK-LABEL: @reschedule_extract( -; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: ret <4 x float> [[TMP1]] +; THRESHOLD-LABEL: @reschedule_extract( +; THRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; THRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; NOTHRESHOLD-LABEL: @reschedule_extract( +; NOTHRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; NOTHRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; MINTREESIZE-LABEL: @reschedule_extract( +; MINTREESIZE-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[B:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[B]], i32 0 +; MINTREESIZE-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[A:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[TMP7:%.*]] = extractelement <4 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[TMP8:%.*]] = extractelement <4 x float> [[A]], i32 0 +; MINTREESIZE-NEXT: [[TMP9:%.*]] = insertelement <2 x float> poison, float [[TMP8]], i32 0 +; MINTREESIZE-NEXT: [[TMP10:%.*]] = insertelement <2 x float> [[TMP9]], float [[TMP4]], i32 1 +; MINTREESIZE-NEXT: [[TMP11:%.*]] = insertelement <2 x float> poison, float [[TMP7]], i32 0 +; MINTREESIZE-NEXT: [[TMP12:%.*]] = insertelement <2 x float> [[TMP11]], float [[TMP3]], i32 1 +; MINTREESIZE-NEXT: [[TMP13:%.*]] = insertelement <2 x float> poison, float [[TMP6]], i32 0 +; MINTREESIZE-NEXT: [[TMP14:%.*]] = insertelement <2 x float> [[TMP13]], float [[TMP2]], i32 1 +; MINTREESIZE-NEXT: [[TMP15:%.*]] = insertelement <2 x float> poison, float [[TMP5]], i32 0 +; MINTREESIZE-NEXT: [[TMP16:%.*]] = insertelement <2 x float> [[TMP15]], float [[TMP1]], i32 1 +; MINTREESIZE-NEXT: [[TMP17:%.*]] = fadd <4 x float> [[A]], [[B]] +; MINTREESIZE-NEXT: ret <4 x float> [[TMP17]] ; %a0 = extractelement <4 x float> %a, i32 0 %b0 = extractelement <4 x float> %b, i32 0 @@ -376,9 +479,33 @@ ; Check that cost model for vectorization takes credit for ; instructions that are erased. define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) { -; CHECK-LABEL: @take_credit( -; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: ret <4 x float> [[TMP1]] +; THRESHOLD-LABEL: @take_credit( +; THRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; THRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; NOTHRESHOLD-LABEL: @take_credit( +; NOTHRESHOLD-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]] +; NOTHRESHOLD-NEXT: ret <4 x float> [[TMP1]] +; +; MINTREESIZE-LABEL: @take_credit( +; MINTREESIZE-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[B:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[B]], i32 0 +; MINTREESIZE-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[A:%.*]], i32 3 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[TMP7:%.*]] = extractelement <4 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[TMP8:%.*]] = extractelement <4 x float> [[A]], i32 0 +; MINTREESIZE-NEXT: [[TMP9:%.*]] = insertelement <2 x float> poison, float [[TMP8]], i32 0 +; MINTREESIZE-NEXT: [[TMP10:%.*]] = insertelement <2 x float> [[TMP9]], float [[TMP4]], i32 1 +; MINTREESIZE-NEXT: [[TMP11:%.*]] = insertelement <2 x float> poison, float [[TMP7]], i32 0 +; MINTREESIZE-NEXT: [[TMP12:%.*]] = insertelement <2 x float> [[TMP11]], float [[TMP3]], i32 1 +; MINTREESIZE-NEXT: [[TMP13:%.*]] = insertelement <2 x float> poison, float [[TMP6]], i32 0 +; MINTREESIZE-NEXT: [[TMP14:%.*]] = insertelement <2 x float> [[TMP13]], float [[TMP2]], i32 1 +; MINTREESIZE-NEXT: [[TMP15:%.*]] = insertelement <2 x float> poison, float [[TMP5]], i32 0 +; MINTREESIZE-NEXT: [[TMP16:%.*]] = insertelement <2 x float> [[TMP15]], float [[TMP1]], i32 1 +; MINTREESIZE-NEXT: [[TMP17:%.*]] = fadd <4 x float> [[A]], [[B]] +; MINTREESIZE-NEXT: ret <4 x float> [[TMP17]] ; %a0 = extractelement <4 x float> %a, i32 0 %b0 = extractelement <4 x float> %b, i32 0 @@ -426,9 +553,49 @@ } define <8 x float> @_vadd256(<8 x float> %a, <8 x float> %b) local_unnamed_addr #0 { -; CHECK-LABEL: @_vadd256( -; CHECK-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]] -; CHECK-NEXT: ret <8 x float> [[TMP1]] +; THRESHOLD-LABEL: @_vadd256( +; THRESHOLD-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]] +; THRESHOLD-NEXT: ret <8 x float> [[TMP1]] +; +; NOTHRESHOLD-LABEL: @_vadd256( +; NOTHRESHOLD-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]] +; NOTHRESHOLD-NEXT: ret <8 x float> [[TMP1]] +; +; MINTREESIZE-LABEL: @_vadd256( +; MINTREESIZE-NEXT: [[TMP1:%.*]] = extractelement <8 x float> [[B:%.*]], i32 7 +; MINTREESIZE-NEXT: [[TMP2:%.*]] = extractelement <8 x float> [[B]], i32 6 +; MINTREESIZE-NEXT: [[TMP3:%.*]] = extractelement <8 x float> [[B]], i32 5 +; MINTREESIZE-NEXT: [[TMP4:%.*]] = extractelement <8 x float> [[B]], i32 4 +; MINTREESIZE-NEXT: [[TMP5:%.*]] = extractelement <8 x float> [[B]], i32 3 +; MINTREESIZE-NEXT: [[TMP6:%.*]] = extractelement <8 x float> [[B]], i32 2 +; MINTREESIZE-NEXT: [[TMP7:%.*]] = extractelement <8 x float> [[B]], i32 1 +; MINTREESIZE-NEXT: [[TMP8:%.*]] = extractelement <8 x float> [[B]], i32 0 +; MINTREESIZE-NEXT: [[TMP9:%.*]] = extractelement <8 x float> [[A:%.*]], i32 7 +; MINTREESIZE-NEXT: [[TMP10:%.*]] = extractelement <8 x float> [[A]], i32 6 +; MINTREESIZE-NEXT: [[TMP11:%.*]] = extractelement <8 x float> [[A]], i32 5 +; MINTREESIZE-NEXT: [[TMP12:%.*]] = extractelement <8 x float> [[A]], i32 4 +; MINTREESIZE-NEXT: [[TMP13:%.*]] = extractelement <8 x float> [[A]], i32 3 +; MINTREESIZE-NEXT: [[TMP14:%.*]] = extractelement <8 x float> [[A]], i32 2 +; MINTREESIZE-NEXT: [[TMP15:%.*]] = extractelement <8 x float> [[A]], i32 1 +; MINTREESIZE-NEXT: [[TMP16:%.*]] = extractelement <8 x float> [[A]], i32 0 +; MINTREESIZE-NEXT: [[TMP17:%.*]] = insertelement <2 x float> poison, float [[TMP16]], i32 0 +; MINTREESIZE-NEXT: [[TMP18:%.*]] = insertelement <2 x float> [[TMP17]], float [[TMP8]], i32 1 +; MINTREESIZE-NEXT: [[TMP19:%.*]] = insertelement <2 x float> poison, float [[TMP15]], i32 0 +; MINTREESIZE-NEXT: [[TMP20:%.*]] = insertelement <2 x float> [[TMP19]], float [[TMP7]], i32 1 +; MINTREESIZE-NEXT: [[TMP21:%.*]] = insertelement <2 x float> poison, float [[TMP14]], i32 0 +; MINTREESIZE-NEXT: [[TMP22:%.*]] = insertelement <2 x float> [[TMP21]], float [[TMP6]], i32 1 +; MINTREESIZE-NEXT: [[TMP23:%.*]] = insertelement <2 x float> poison, float [[TMP13]], i32 0 +; MINTREESIZE-NEXT: [[TMP24:%.*]] = insertelement <2 x float> [[TMP23]], float [[TMP5]], i32 1 +; MINTREESIZE-NEXT: [[TMP25:%.*]] = insertelement <2 x float> poison, float [[TMP12]], i32 0 +; MINTREESIZE-NEXT: [[TMP26:%.*]] = insertelement <2 x float> [[TMP25]], float [[TMP4]], i32 1 +; MINTREESIZE-NEXT: [[TMP27:%.*]] = insertelement <2 x float> poison, float [[TMP11]], i32 0 +; MINTREESIZE-NEXT: [[TMP28:%.*]] = insertelement <2 x float> [[TMP27]], float [[TMP3]], i32 1 +; MINTREESIZE-NEXT: [[TMP29:%.*]] = insertelement <2 x float> poison, float [[TMP10]], i32 0 +; MINTREESIZE-NEXT: [[TMP30:%.*]] = insertelement <2 x float> [[TMP29]], float [[TMP2]], i32 1 +; MINTREESIZE-NEXT: [[TMP31:%.*]] = insertelement <2 x float> poison, float [[TMP9]], i32 0 +; MINTREESIZE-NEXT: [[TMP32:%.*]] = insertelement <2 x float> [[TMP31]], float [[TMP1]], i32 1 +; MINTREESIZE-NEXT: [[TMP33:%.*]] = fadd <8 x float> [[A]], [[B]] +; MINTREESIZE-NEXT: ret <8 x float> [[TMP33]] ; %vecext = extractelement <8 x float> %a, i32 0 %vecext1 = extractelement <8 x float> %b, i32 0