207 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --filter-out-after "^scalar.ph" --version 52; RUN: opt < %s -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=2 -S | FileCheck %s3 4define void @test1(ptr noalias nocapture %a, ptr noalias nocapture readonly %b) {5; CHECK-LABEL: define void @test1(6; CHECK-SAME: ptr noalias captures(none) [[A:%.*]], ptr noalias readonly captures(none) [[B:%.*]]) {7; CHECK-NEXT: [[ENTRY:.*:]]8; CHECK-NEXT: br label %[[VECTOR_PH:.*]]9; CHECK: [[VECTOR_PH]]:10; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]11; CHECK: [[VECTOR_BODY]]:12; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]13; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[INDEX]]14; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds float, ptr [[TMP0]], i64 215; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x float>, ptr [[TMP0]], align 416; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <2 x float>, ptr [[TMP7]], align 417; CHECK-NEXT: [[TMP1:%.*]] = fcmp ogt <2 x float> [[WIDE_LOAD]], splat (float 1.000000e+02)18; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x i1> [[TMP1]], i32 019; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x i1> [[TMP1]], i32 120; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <2 x float> [[WIDE_LOAD1]], splat (float 1.000000e+02)21; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x i1> [[TMP2]], i32 022; CHECK-NEXT: [[TMP13:%.*]] = extractelement <2 x i1> [[TMP2]], i32 123; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP4]])24; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP5]])25; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP6]])26; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP13]])27; CHECK-NEXT: [[TMP8:%.*]] = fadd <2 x float> [[WIDE_LOAD]], splat (float 1.000000e+00)28; CHECK-NEXT: [[TMP9:%.*]] = fadd <2 x float> [[WIDE_LOAD1]], splat (float 1.000000e+00)29; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[INDEX]]30; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds float, ptr [[TMP10]], i64 231; CHECK-NEXT: store <2 x float> [[TMP8]], ptr [[TMP10]], align 432; CHECK-NEXT: store <2 x float> [[TMP9]], ptr [[TMP11]], align 433; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 434; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 160035; CHECK-NEXT: br i1 [[TMP12]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]36; CHECK: [[MIDDLE_BLOCK]]:37; CHECK-NEXT: br label %[[FOR_END:.*]]38; CHECK: [[FOR_END]]:39; CHECK-NEXT: ret void40;41entry:42 br label %for.body43 44for.body: ; preds = %for.body, %entry45 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]46 %arrayidx = getelementptr inbounds float, ptr %b, i64 %indvars.iv47 %0 = load float, ptr %arrayidx, align 448 %cmp1 = fcmp ogt float %0, 1.000000e+0249 tail call void @llvm.assume(i1 %cmp1)50 %add = fadd float %0, 1.000000e+0051 %arrayidx5 = getelementptr inbounds float, ptr %a, i64 %indvars.iv52 store float %add, ptr %arrayidx5, align 453 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 154 %exitcond = icmp eq i64 %indvars.iv, 159955 br i1 %exitcond, label %for.end, label %for.body56 57for.end: ; preds = %for.body58 ret void59}60 61declare void @llvm.assume(i1) #062 63attributes #0 = { nounwind willreturn }64 65define void @test2(ptr noalias %a, ptr noalias %b) {66; CHECK-LABEL: define void @test2(67; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]]) {68; CHECK-NEXT: [[ENTRY:.*:]]69; CHECK-NEXT: [[PTRINT:%.*]] = ptrtoint ptr [[A]] to i6470; CHECK-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 3171; CHECK-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 072; CHECK-NEXT: [[PTRINT2:%.*]] = ptrtoint ptr [[B]] to i6473; CHECK-NEXT: [[MASKEDPTR3:%.*]] = and i64 [[PTRINT2]], 3174; CHECK-NEXT: [[MASKCOND4:%.*]] = icmp eq i64 [[MASKEDPTR3]], 075; CHECK-NEXT: br label %[[VECTOR_PH:.*]]76; CHECK: [[VECTOR_PH]]:77; CHECK-NEXT: tail call void @llvm.assume(i1 [[MASKCOND]])78; CHECK-NEXT: tail call void @llvm.assume(i1 [[MASKCOND4]])79; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]80; CHECK: [[VECTOR_BODY]]:81; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]82; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[INDEX]]83; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds float, ptr [[TMP3]], i64 284; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x float>, ptr [[TMP3]], align 485; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <2 x float>, ptr [[TMP4]], align 486; CHECK-NEXT: [[TMP5:%.*]] = fadd <2 x float> [[WIDE_LOAD]], splat (float 1.000000e+00)87; CHECK-NEXT: [[TMP6:%.*]] = fadd <2 x float> [[WIDE_LOAD1]], splat (float 1.000000e+00)88; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[INDEX]]89; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds float, ptr [[TMP7]], i64 290; CHECK-NEXT: store <2 x float> [[TMP5]], ptr [[TMP7]], align 491; CHECK-NEXT: store <2 x float> [[TMP6]], ptr [[TMP8]], align 492; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 493; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 160094; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]95; CHECK: [[MIDDLE_BLOCK]]:96; CHECK-NEXT: br label %[[FOR_END:.*]]97; CHECK: [[FOR_END]]:98; CHECK-NEXT: ret void99;100entry:101 %ptrint = ptrtoint ptr %a to i64102 %maskedptr = and i64 %ptrint, 31103 %maskcond = icmp eq i64 %maskedptr, 0104 %ptrint2 = ptrtoint ptr %b to i64105 %maskedptr3 = and i64 %ptrint2, 31106 %maskcond4 = icmp eq i64 %maskedptr3, 0107 br label %for.body108 109 110for.body: ; preds = %for.body, %entry111 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]112 tail call void @llvm.assume(i1 %maskcond)113 %arrayidx = getelementptr inbounds float, ptr %a, i64 %indvars.iv114 %2 = load float, ptr %arrayidx, align 4115 %add = fadd float %2, 1.000000e+00116 tail call void @llvm.assume(i1 %maskcond4)117 %arrayidx5 = getelementptr inbounds float, ptr %b, i64 %indvars.iv118 store float %add, ptr %arrayidx5, align 4119 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1120 %exitcond = icmp eq i64 %indvars.iv, 1599121 br i1 %exitcond, label %for.end, label %for.body122 123for.end: ; preds = %for.body124 ret void125}126 127; Test case for PR43620. Make sure we can vectorize with predication in presence128; of assume calls. For now, check that we drop all assumes in predicated blocks129; in the vector body.130define void @predicated_assume(ptr noalias nocapture readonly %a, ptr noalias nocapture %b, i32 %n) {131; Check that the vector.body does not contain any assumes.132; CHECK-LABEL: define void @predicated_assume(133; CHECK-SAME: ptr noalias readonly captures(none) [[A:%.*]], ptr noalias captures(none) [[B:%.*]], i32 [[N:%.*]]) {134; CHECK-NEXT: [[ENTRY:.*:]]135; CHECK-NEXT: [[CMP15:%.*]] = icmp eq i32 [[N]], 0136; CHECK-NEXT: br i1 [[CMP15]], [[FOR_COND_CLEANUP:label %.*]], label %[[FOR_BODY_PREHEADER:.*]]137; CHECK: [[FOR_BODY_PREHEADER]]:138; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[N]] to i64139; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP0]], 4140; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]141; CHECK: [[VECTOR_PH]]:142; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP0]], 4143; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP0]], [[N_MOD_VF]]144; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]145; CHECK: [[VECTOR_BODY]]:146; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]147; CHECK-NEXT: [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]148; CHECK-NEXT: [[STEP_ADD:%.*]] = add <2 x i64> [[VEC_IND]], splat (i64 2)149; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <2 x i64> [[VEC_IND]], splat (i64 495616)150; CHECK-NEXT: [[TMP2:%.*]] = icmp ult <2 x i64> [[STEP_ADD]], splat (i64 495616)151; CHECK-NEXT: [[PREDPHI:%.*]] = select <2 x i1> [[TMP1]], <2 x float> splat (float 2.300000e+01), <2 x float> splat (float 4.200000e+01)152; CHECK-NEXT: [[PREDPHI1:%.*]] = select <2 x i1> [[TMP2]], <2 x float> splat (float 2.300000e+01), <2 x float> splat (float 4.200000e+01)153; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[INDEX]]154; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds float, ptr [[TMP3]], i64 2155; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x float>, ptr [[TMP3]], align 4156; CHECK-NEXT: [[WIDE_LOAD2:%.*]] = load <2 x float>, ptr [[TMP4]], align 4157; CHECK-NEXT: [[TMP5:%.*]] = fmul <2 x float> [[PREDPHI]], [[WIDE_LOAD]]158; CHECK-NEXT: [[TMP6:%.*]] = fmul <2 x float> [[PREDPHI1]], [[WIDE_LOAD2]]159; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[INDEX]]160; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds float, ptr [[TMP7]], i64 2161; CHECK-NEXT: store <2 x float> [[TMP5]], ptr [[TMP7]], align 4162; CHECK-NEXT: store <2 x float> [[TMP6]], ptr [[TMP8]], align 4163; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4164; CHECK-NEXT: [[VEC_IND_NEXT]] = add nuw nsw <2 x i64> [[STEP_ADD]], splat (i64 2)165; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]166; CHECK-NEXT: br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]167; CHECK: [[MIDDLE_BLOCK]]:168; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP0]], [[N_VEC]]169; CHECK-NEXT: br i1 [[CMP_N]], [[FOR_COND_CLEANUP_LOOPEXIT:label %.*]], label %[[SCALAR_PH]]170; CHECK: [[SCALAR_PH]]:171;172entry:173 %cmp15 = icmp eq i32 %n, 0174 br i1 %cmp15, label %for.cond.cleanup, label %for.body.preheader175 176for.body.preheader: ; preds = %entry177 %0 = zext i32 %n to i64178 br label %for.body179 180for.cond.cleanup.loopexit: ; preds = %if.end5181 br label %for.cond.cleanup182 183for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry184 ret void185 186for.body: ; preds = %for.body.preheader, %if.end5187 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %if.end5 ]188 %cmp1 = icmp ult i64 %indvars.iv, 495616189 br i1 %cmp1, label %if.end5, label %if.else190 191if.else: ; preds = %for.body192 %cmp2 = icmp ult i64 %indvars.iv, 991232193 tail call void @llvm.assume(i1 %cmp2)194 br label %if.end5195 196if.end5: ; preds = %for.body, %if.else197 %x.0 = phi float [ 4.200000e+01, %if.else ], [ 2.300000e+01, %for.body ]198 %arrayidx = getelementptr inbounds float, ptr %a, i64 %indvars.iv199 %1 = load float, ptr %arrayidx, align 4200 %mul = fmul float %x.0, %1201 %arrayidx7 = getelementptr inbounds float, ptr %b, i64 %indvars.iv202 store float %mul, ptr %arrayidx7, align 4203 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1204 %cmp = icmp eq i64 %indvars.iv.next, %0205 br i1 %cmp, label %for.cond.cleanup.loopexit, label %for.body206}207