836 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -mtriple=thumbv8.1m.main-arm-eabihf -mattr=+mve.fp \3; RUN: -tail-predication=enabled -passes=loop-vectorize -S < %s | \4; RUN: FileCheck %s5 6target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"7 8define void @trunc_not_allowed_different_vec_elemns(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C, ptr noalias nocapture %D) #0 {9; CHECK-LABEL: @trunc_not_allowed_different_vec_elemns(10; CHECK-NEXT: entry:11; CHECK-NEXT: br label [[VECTOR_PH:%.*]]12; CHECK: vector.ph:13; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]14; CHECK: vector.body:15; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]16; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i32 [[INDEX]]17; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 418; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i32 [[INDEX]]19; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i32>, ptr [[TMP3]], align 420; CHECK-NEXT: [[TMP5:%.*]] = add nsw <4 x i32> [[WIDE_LOAD1]], [[WIDE_LOAD]]21; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[INDEX]]22; CHECK-NEXT: store <4 x i32> [[TMP5]], ptr [[TMP6]], align 423; CHECK-NEXT: [[TMP8:%.*]] = trunc <4 x i32> [[TMP5]] to <4 x i16>24; CHECK-NEXT: [[TMP9:%.*]] = shl <4 x i16> [[TMP8]], splat (i16 1)25; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i16, ptr [[D:%.*]], i32 [[INDEX]]26; CHECK-NEXT: store <4 x i16> [[TMP9]], ptr [[TMP10]], align 227; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 428; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i32 [[INDEX_NEXT]], 42829; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]30; CHECK: middle.block:31; CHECK-NEXT: br label [[SCALAR_PH:%.*]]32; CHECK: scalar.ph:33; CHECK-NEXT: br label [[FOR_BODY:%.*]]34; CHECK: for.cond.cleanup:35; CHECK-NEXT: ret void36; CHECK: for.body:37; CHECK-NEXT: [[I_021:%.*]] = phi i32 [ 428, [[SCALAR_PH]] ], [ [[ADD9:%.*]], [[FOR_BODY]] ]38; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[I_021]]39; CHECK-NEXT: [[TMP13:%.*]] = load i32, ptr [[ARRAYIDX]], align 440; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[C]], i32 [[I_021]]41; CHECK-NEXT: [[TMP14:%.*]] = load i32, ptr [[ARRAYIDX1]], align 442; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP14]], [[TMP13]]43; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[I_021]]44; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX2]], align 445; CHECK-NEXT: [[ADD_TR:%.*]] = trunc i32 [[ADD]] to i1646; CHECK-NEXT: [[CONV7:%.*]] = shl i16 [[ADD_TR]], 147; CHECK-NEXT: [[ARRAYIDX8:%.*]] = getelementptr inbounds i16, ptr [[D]], i32 [[I_021]]48; CHECK-NEXT: store i16 [[CONV7]], ptr [[ARRAYIDX8]], align 249; CHECK-NEXT: [[ADD9]] = add nuw nsw i32 [[I_021]], 150; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD9]], 43151; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]52;53entry:54 br label %for.body55 56for.cond.cleanup:57 ret void58 59for.body:60 %i.021 = phi i32 [ 0, %entry ], [ %add9, %for.body ]61 %arrayidx = getelementptr inbounds i32, ptr %B, i32 %i.02162 %0 = load i32, ptr %arrayidx, align 463 %arrayidx1 = getelementptr inbounds i32, ptr %C, i32 %i.02164 %1 = load i32, ptr %arrayidx1, align 465 %add = add nsw i32 %1, %066 %arrayidx2 = getelementptr inbounds i32, ptr %A, i32 %i.02167 store i32 %add, ptr %arrayidx2, align 468 %add.tr = trunc i32 %add to i1669 %conv7 = shl i16 %add.tr, 170 %arrayidx8 = getelementptr inbounds i16, ptr %D, i32 %i.02171 store i16 %conv7, ptr %arrayidx8, align 272 %add9 = add nuw nsw i32 %i.021, 173 %exitcond = icmp eq i32 %add9, 43174 br i1 %exitcond, label %for.cond.cleanup, label %for.body75}76 77define void @unsupported_i64_type(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C) #0 {78; CHECK-LABEL: @unsupported_i64_type(79; CHECK-NEXT: entry:80; CHECK-NEXT: br label [[FOR_BODY:%.*]]81; CHECK: for.cond.cleanup:82; CHECK-NEXT: ret void83; CHECK: for.body:84; CHECK-NEXT: [[I_09:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[ADD3:%.*]], [[FOR_BODY]] ]85; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[B:%.*]], i32 [[I_09]]86; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 887; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i64, ptr [[C:%.*]], i32 [[I_09]]88; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[ARRAYIDX1]], align 889; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP1]], [[TMP0]]90; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i32 [[I_09]]91; CHECK-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX2]], align 892; CHECK-NEXT: [[ADD3]] = add nuw nsw i32 [[I_09]], 193; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD3]], 43194; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]95;96entry:97 br label %for.body98 99for.cond.cleanup:100 ret void101 102for.body:103 %i.09 = phi i32 [ 0, %entry ], [ %add3, %for.body ]104 %arrayidx = getelementptr inbounds i64, ptr %B, i32 %i.09105 %0 = load i64, ptr %arrayidx, align 8106 %arrayidx1 = getelementptr inbounds i64, ptr %C, i32 %i.09107 %1 = load i64, ptr %arrayidx1, align 8108 %add = add nsw i64 %1, %0109 %arrayidx2 = getelementptr inbounds i64, ptr %A, i32 %i.09110 store i64 %add, ptr %arrayidx2, align 8111 %add3 = add nuw nsw i32 %i.09, 1112 %exitcond = icmp eq i32 %add3, 431113 br i1 %exitcond, label %for.cond.cleanup, label %for.body114}115 116define void @narrowing_load_not_allowed(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C) #0 {117; CHECK-LABEL: @narrowing_load_not_allowed(118; CHECK-NEXT: entry:119; CHECK-NEXT: br label [[VECTOR_PH:%.*]]120; CHECK: vector.ph:121; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]122; CHECK: vector.body:123; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]124; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i16, ptr [[C:%.*]], i32 [[INDEX]]125; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <8 x i16>, ptr [[TMP1]], align 2126; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i8, ptr [[B:%.*]], i32 [[INDEX]]127; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <8 x i8>, ptr [[TMP3]], align 1128; CHECK-NEXT: [[TMP5:%.*]] = trunc <8 x i16> [[WIDE_LOAD]] to <8 x i8>129; CHECK-NEXT: [[TMP6:%.*]] = add <8 x i8> [[WIDE_LOAD1]], [[TMP5]]130; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i8, ptr [[A:%.*]], i32 [[INDEX]]131; CHECK-NEXT: store <8 x i8> [[TMP6]], ptr [[TMP7]], align 1132; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8133; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i32 [[INDEX_NEXT]], 424134; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]135; CHECK: middle.block:136; CHECK-NEXT: br label [[SCALAR_PH:%.*]]137; CHECK: scalar.ph:138; CHECK-NEXT: br label [[FOR_BODY:%.*]]139; CHECK: for.cond.cleanup:140; CHECK-NEXT: ret void141; CHECK: for.body:142; CHECK-NEXT: [[I_012:%.*]] = phi i32 [ 424, [[SCALAR_PH]] ], [ [[ADD6:%.*]], [[FOR_BODY]] ]143; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i16, ptr [[C]], i32 [[I_012]]144; CHECK-NEXT: [[TMP10:%.*]] = load i16, ptr [[ARRAYIDX]], align 2145; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[B]], i32 [[I_012]]146; CHECK-NEXT: [[TMP11:%.*]] = load i8, ptr [[ARRAYIDX1]], align 1147; CHECK-NEXT: [[CONV3:%.*]] = trunc i16 [[TMP10]] to i8148; CHECK-NEXT: [[ADD:%.*]] = add i8 [[TMP11]], [[CONV3]]149; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds i8, ptr [[A]], i32 [[I_012]]150; CHECK-NEXT: store i8 [[ADD]], ptr [[ARRAYIDX5]], align 1151; CHECK-NEXT: [[ADD6]] = add nuw nsw i32 [[I_012]], 1152; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD6]], 431153; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]154;155entry:156 br label %for.body157 158for.cond.cleanup: ; preds = %for.body159 ret void160 161for.body: ; preds = %for.body, %entry162 %i.012 = phi i32 [ 0, %entry ], [ %add6, %for.body ]163 %arrayidx = getelementptr inbounds i16, ptr %C, i32 %i.012164 %0 = load i16, ptr %arrayidx, align 2165 %arrayidx1 = getelementptr inbounds i8, ptr %B, i32 %i.012166 %1 = load i8, ptr %arrayidx1, align 1167 %conv3 = trunc i16 %0 to i8168 %add = add i8 %1, %conv3169 %arrayidx5 = getelementptr inbounds i8, ptr %A, i32 %i.012170 store i8 %add, ptr %arrayidx5, align 1171 %add6 = add nuw nsw i32 %i.012, 1172 %exitcond = icmp eq i32 %add6, 431173 br i1 %exitcond, label %for.cond.cleanup, label %for.body174}175 176; This is a trunc not connected to a store, so we don't allow this.177; TODO: this is conservative, because the trunc is only used in the178; loop control statements, and thus not affecting element sizes, so179; we could allow this case.180;181define void @trunc_not_allowed(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C) #0 {182; CHECK-LABEL: @trunc_not_allowed(183; CHECK-NEXT: entry:184; CHECK-NEXT: br label [[VECTOR_PH:%.*]]185; CHECK: vector.ph:186; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]187; CHECK: vector.body:188; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]189; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i32 [[INDEX]]190; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4191; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i32 [[INDEX]]192; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i32>, ptr [[TMP3]], align 4193; CHECK-NEXT: [[TMP5:%.*]] = add nsw <4 x i32> [[WIDE_LOAD1]], [[WIDE_LOAD]]194; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[INDEX]]195; CHECK-NEXT: store <4 x i32> [[TMP5]], ptr [[TMP6]], align 4196; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4197; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[INDEX_NEXT]], 428198; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]199; CHECK: middle.block:200; CHECK-NEXT: br label [[SCALAR_PH:%.*]]201; CHECK: scalar.ph:202; CHECK-NEXT: br label [[FOR_BODY:%.*]]203; CHECK: for.cond.cleanup:204; CHECK-NEXT: ret void205; CHECK: for.body:206; CHECK-NEXT: [[I_09:%.*]] = phi i32 [ 428, [[SCALAR_PH]] ], [ [[ADD3:%.*]], [[FOR_BODY]] ]207; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[I_09]]208; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[ARRAYIDX]], align 4209; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[C]], i32 [[I_09]]210; CHECK-NEXT: [[TMP10:%.*]] = load i32, ptr [[ARRAYIDX1]], align 4211; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP10]], [[TMP9]]212; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[I_09]]213; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX2]], align 4214; CHECK-NEXT: [[ADD3]] = add nuw nsw i32 [[I_09]], 1215; CHECK-NEXT: [[ADD_IV:%.*]] = trunc i32 [[ADD3]] to i16216; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i16 [[ADD_IV]], 431217; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]218;219entry:220 br label %for.body221 222for.cond.cleanup:223 ret void224 225for.body:226 %i.09 = phi i32 [ 0, %entry ], [ %add3, %for.body ]227 %arrayidx = getelementptr inbounds i32, ptr %B, i32 %i.09228 %0 = load i32, ptr %arrayidx, align 4229 %arrayidx1 = getelementptr inbounds i32, ptr %C, i32 %i.09230 %1 = load i32, ptr %arrayidx1, align 4231 %add = add nsw i32 %1, %0232 %arrayidx2 = getelementptr inbounds i32, ptr %A, i32 %i.09233 store i32 %add, ptr %arrayidx2, align 4234 %add3 = add nuw nsw i32 %i.09, 1235 236 %add.iv = trunc i32 %add3 to i16237 238 %exitcond = icmp eq i16 %add.iv, 431239 br i1 %exitcond, label %for.cond.cleanup, label %for.body240}241 242; Test directions for array indices i and N-1. I.e. check strides 1 and -1, and243; force vectorisation with a loop hint.244;245define void @strides_different_direction(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C, i32 %N) #0 {246; CHECK-LABEL: @strides_different_direction(247; CHECK-NEXT: entry:248; CHECK-NEXT: br label [[VECTOR_PH:%.*]]249; CHECK: vector.ph:250; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]251; CHECK: vector.body:252; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]253; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i32 [[INDEX]]254; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4255; CHECK-NEXT: [[TMP3:%.*]] = sub nsw i32 [[N:%.*]], [[INDEX]]256; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i32 [[TMP3]]257; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[TMP4]], i32 0258; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i32 -3259; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i32>, ptr [[TMP6]], align 4260; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x i32> [[WIDE_LOAD1]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>261; CHECK-NEXT: [[TMP7:%.*]] = add nsw <4 x i32> [[REVERSE]], [[WIDE_LOAD]]262; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[INDEX]]263; CHECK-NEXT: store <4 x i32> [[TMP7]], ptr [[TMP8]], align 4264; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4265; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i32 [[INDEX_NEXT]], 428266; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]267; CHECK: middle.block:268; CHECK-NEXT: br label [[SCALAR_PH:%.*]]269; CHECK: scalar.ph:270; CHECK-NEXT: br label [[FOR_BODY:%.*]]271; CHECK: for.cond.cleanup:272; CHECK-NEXT: ret void273; CHECK: for.body:274; CHECK-NEXT: [[I_09:%.*]] = phi i32 [ 428, [[SCALAR_PH]] ], [ [[ADD3:%.*]], [[FOR_BODY]] ]275; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[I_09]]276; CHECK-NEXT: [[TMP11:%.*]] = load i32, ptr [[ARRAYIDX]], align 4277; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[N]], [[I_09]]278; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[C]], i32 [[SUB]]279; CHECK-NEXT: [[TMP12:%.*]] = load i32, ptr [[ARRAYIDX1]], align 4280; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP12]], [[TMP11]]281; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[I_09]]282; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX2]], align 4283; CHECK-NEXT: [[ADD3]] = add nuw nsw i32 [[I_09]], 1284; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD3]], 431285; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]286;287entry:288 br label %for.body289 290for.cond.cleanup:291 ret void292 293for.body:294 %i.09 = phi i32 [ 0, %entry ], [ %add3, %for.body ]295 %arrayidx = getelementptr inbounds i32, ptr %B, i32 %i.09296 %0 = load i32, ptr %arrayidx, align 4297 %sub = sub nsw i32 %N, %i.09298 %arrayidx1 = getelementptr inbounds i32, ptr %C, i32 %sub299 %1 = load i32, ptr %arrayidx1, align 4300 %add = add nsw i32 %1, %0301 %arrayidx2 = getelementptr inbounds i32, ptr %A, i32 %i.09302 store i32 %add, ptr %arrayidx2, align 4303 %add3 = add nuw nsw i32 %i.09, 1304 %exitcond = icmp eq i32 %add3, 431305 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !10306}307 308define void @too_many_loop_blocks(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C) #0 {309; CHECK-LABEL: @too_many_loop_blocks(310; CHECK-NEXT: entry:311; CHECK-NEXT: br label [[VECTOR_PH:%.*]]312; CHECK: vector.ph:313; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]314; CHECK: vector.body:315; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]316; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i32 [[INDEX]]317; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4318; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i32 [[INDEX]]319; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x i32>, ptr [[TMP3]], align 4320; CHECK-NEXT: [[TMP5:%.*]] = add nsw <4 x i32> [[WIDE_LOAD1]], [[WIDE_LOAD]]321; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[INDEX]]322; CHECK-NEXT: store <4 x i32> [[TMP5]], ptr [[TMP6]], align 4323; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4324; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[INDEX_NEXT]], 428325; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]326; CHECK: middle.block:327; CHECK-NEXT: br label [[SCALAR_PH:%.*]]328; CHECK: scalar.ph:329; CHECK-NEXT: br label [[FOR_BODY:%.*]]330; CHECK: for.cond.cleanup:331; CHECK-NEXT: ret void332; CHECK: for.body:333; CHECK-NEXT: [[I_09:%.*]] = phi i32 [ 428, [[SCALAR_PH]] ], [ [[ADD3:%.*]], [[LOOPINCR:%.*]] ]334; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[I_09]]335; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[ARRAYIDX]], align 4336; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[C]], i32 [[I_09]]337; CHECK-NEXT: [[TMP10:%.*]] = load i32, ptr [[ARRAYIDX1]], align 4338; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP10]], [[TMP9]]339; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[I_09]]340; CHECK-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX2]], align 4341; CHECK-NEXT: br label [[LOOPINCR]]342; CHECK: loopincr:343; CHECK-NEXT: [[ADD3]] = add nuw nsw i32 [[I_09]], 1344; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD3]], 431345; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]346;347entry:348 br label %for.body349 350for.cond.cleanup:351 ret void352 353for.body:354 %i.09 = phi i32 [ 0, %entry ], [ %add3, %loopincr ]355 %arrayidx = getelementptr inbounds i32, ptr %B, i32 %i.09356 %0 = load i32, ptr %arrayidx, align 4357 %arrayidx1 = getelementptr inbounds i32, ptr %C, i32 %i.09358 %1 = load i32, ptr %arrayidx1, align 4359 %add = add nsw i32 %1, %0360 %arrayidx2 = getelementptr inbounds i32, ptr %A, i32 %i.09361 store i32 %add, ptr %arrayidx2, align 4362 br label %loopincr363 364loopincr:365 %add3 = add nuw nsw i32 %i.09, 1366 %exitcond = icmp eq i32 %add3, 431367 br i1 %exitcond, label %for.cond.cleanup, label %for.body368}369 370define void @double(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C) #0 {371; CHECK-LABEL: @double(372; CHECK-NEXT: entry:373; CHECK-NEXT: br label [[FOR_BODY:%.*]]374; CHECK: for.cond.cleanup:375; CHECK-NEXT: ret void376; CHECK: for.body:377; CHECK-NEXT: [[I_09:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[ADD3:%.*]], [[FOR_BODY]] ]378; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[B:%.*]], i32 [[I_09]]379; CHECK-NEXT: [[TMP0:%.*]] = load double, ptr [[ARRAYIDX]], align 8380; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds double, ptr [[C:%.*]], i32 [[I_09]]381; CHECK-NEXT: [[TMP1:%.*]] = load double, ptr [[ARRAYIDX1]], align 8382; CHECK-NEXT: [[ADD:%.*]] = fadd fast double [[TMP1]], [[TMP0]]383; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds double, ptr [[A:%.*]], i32 [[I_09]]384; CHECK-NEXT: store double [[ADD]], ptr [[ARRAYIDX2]], align 8385; CHECK-NEXT: [[ADD3]] = add nuw nsw i32 [[I_09]], 1386; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD3]], 431387; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]388;389entry:390 br label %for.body391 392for.cond.cleanup:393 ret void394 395for.body:396 %i.09 = phi i32 [ 0, %entry ], [ %add3, %for.body ]397 %arrayidx = getelementptr inbounds double, ptr %B, i32 %i.09398 %0 = load double, ptr %arrayidx, align 8399 %arrayidx1 = getelementptr inbounds double, ptr %C, i32 %i.09400 %1 = load double, ptr %arrayidx1, align 8401 %add = fadd fast double %1, %0402 %arrayidx2 = getelementptr inbounds double, ptr %A, i32 %i.09403 store double %add, ptr %arrayidx2, align 8404 %add3 = add nuw nsw i32 %i.09, 1405 %exitcond = icmp eq i32 %add3, 431406 br i1 %exitcond, label %for.cond.cleanup, label %for.body407}408 409define void @fptrunc_not_allowed(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C, ptr noalias nocapture %D) #0 {410; CHECK-LABEL: @fptrunc_not_allowed(411; CHECK-NEXT: entry:412; CHECK-NEXT: br label [[VECTOR_PH:%.*]]413; CHECK: vector.ph:414; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]415; CHECK: vector.body:416; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]417; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i32 [[INDEX]]418; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4419; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds float, ptr [[C:%.*]], i32 [[INDEX]]420; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <4 x float>, ptr [[TMP3]], align 4421; CHECK-NEXT: [[TMP5:%.*]] = fadd fast <4 x float> [[WIDE_LOAD1]], [[WIDE_LOAD]]422; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds float, ptr [[A:%.*]], i32 [[INDEX]]423; CHECK-NEXT: store <4 x float> [[TMP5]], ptr [[TMP6]], align 4424; CHECK-NEXT: [[TMP8:%.*]] = fptrunc <4 x float> [[TMP5]] to <4 x half>425; CHECK-NEXT: [[TMP9:%.*]] = fmul fast <4 x half> [[TMP8]], splat (half 0xH4000)426; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds half, ptr [[D:%.*]], i32 [[INDEX]]427; CHECK-NEXT: store <4 x half> [[TMP9]], ptr [[TMP10]], align 2428; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4429; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i32 [[INDEX_NEXT]], 428430; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]431; CHECK: middle.block:432; CHECK-NEXT: br label [[SCALAR_PH:%.*]]433; CHECK: scalar.ph:434; CHECK-NEXT: br label [[FOR_BODY:%.*]]435; CHECK: for.cond.cleanup:436; CHECK-NEXT: ret void437; CHECK: for.body:438; CHECK-NEXT: [[I_017:%.*]] = phi i32 [ 428, [[SCALAR_PH]] ], [ [[ADD6:%.*]], [[FOR_BODY]] ]439; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[B]], i32 [[I_017]]440; CHECK-NEXT: [[TMP13:%.*]] = load float, ptr [[ARRAYIDX]], align 4441; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds float, ptr [[C]], i32 [[I_017]]442; CHECK-NEXT: [[TMP14:%.*]] = load float, ptr [[ARRAYIDX1]], align 4443; CHECK-NEXT: [[ADD:%.*]] = fadd fast float [[TMP14]], [[TMP13]]444; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, ptr [[A]], i32 [[I_017]]445; CHECK-NEXT: store float [[ADD]], ptr [[ARRAYIDX2]], align 4446; CHECK-NEXT: [[CONV:%.*]] = fptrunc float [[ADD]] to half447; CHECK-NEXT: [[FACTOR:%.*]] = fmul fast half [[CONV]], 0xH4000448; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds half, ptr [[D]], i32 [[I_017]]449; CHECK-NEXT: store half [[FACTOR]], ptr [[ARRAYIDX5]], align 2450; CHECK-NEXT: [[ADD6]] = add nuw nsw i32 [[I_017]], 1451; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[ADD6]], 431452; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP13:![0-9]+]]453;454entry:455 br label %for.body456 457for.cond.cleanup:458 ret void459 460for.body:461 %i.017 = phi i32 [ 0, %entry ], [ %add6, %for.body ]462 %arrayidx = getelementptr inbounds float, ptr %B, i32 %i.017463 %0 = load float, ptr %arrayidx, align 4464 %arrayidx1 = getelementptr inbounds float, ptr %C, i32 %i.017465 %1 = load float, ptr %arrayidx1, align 4466 %add = fadd fast float %1, %0467 %arrayidx2 = getelementptr inbounds float, ptr %A, i32 %i.017468 store float %add, ptr %arrayidx2, align 4469 %conv = fptrunc float %add to half470 %factor = fmul fast half %conv, 0xH4000471 %arrayidx5 = getelementptr inbounds half, ptr %D, i32 %i.017472 store half %factor, ptr %arrayidx5, align 2473 %add6 = add nuw nsw i32 %i.017, 1474 %exitcond = icmp eq i32 %add6, 431475 br i1 %exitcond, label %for.cond.cleanup, label %for.body476}477 478; This is a select which isn't a max or min (it isn't live-out), that we don't479; want to tail-fold. Because this select will result in some mov lanes,480; which aren't supported by the lowoverhead loop pass, causing the tail-predication481; to be reverted which is expensive and what we would like to avoid.482;483define dso_local void @select_not_allowed(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, ptr noalias nocapture readonly %C, i32 %N, ptr noalias nocapture readonly %Cond) {484; CHECK-LABEL: @select_not_allowed(485; CHECK-NEXT: entry:486; CHECK-NEXT: [[CMP10:%.*]] = icmp sgt i32 [[N:%.*]], 0487; CHECK-NEXT: br i1 [[CMP10]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]488; CHECK: for.body.preheader:489; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4490; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]491; CHECK: vector.ph:492; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4493; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]494; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x ptr> poison, ptr [[C:%.*]], i64 0495; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x ptr> [[BROADCAST_SPLATINSERT]], <4 x ptr> poison, <4 x i32> zeroinitializer496; CHECK-NEXT: [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <4 x ptr> poison, ptr [[B:%.*]], i64 0497; CHECK-NEXT: [[BROADCAST_SPLAT2:%.*]] = shufflevector <4 x ptr> [[BROADCAST_SPLATINSERT1]], <4 x ptr> poison, <4 x i32> zeroinitializer498; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]499; CHECK: vector.body:500; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]501; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]502; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[COND:%.*]], i32 [[INDEX]]503; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4504; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <4 x i32> [[WIDE_LOAD]], zeroinitializer505; CHECK-NEXT: [[TMP4:%.*]] = select <4 x i1> [[TMP3]], <4 x ptr> [[BROADCAST_SPLAT]], <4 x ptr> [[BROADCAST_SPLAT2]]506; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, <4 x ptr> [[TMP4]], <4 x i32> [[VEC_IND]]507; CHECK-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> align 4 [[TMP5]], <4 x i1> splat (i1 true), <4 x i32> poison)508; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[INDEX]]509; CHECK-NEXT: store <4 x i32> [[WIDE_MASKED_GATHER]], ptr [[TMP6]], align 4510; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4511; CHECK-NEXT: [[VEC_IND_NEXT]] = add nuw nsw <4 x i32> [[VEC_IND]], splat (i32 4)512; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]513; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]514; CHECK: middle.block:515; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]516; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]517; CHECK: scalar.ph:518; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ]519; CHECK-NEXT: br label [[FOR_BODY:%.*]]520; CHECK: for.cond.cleanup.loopexit:521; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]522; CHECK: for.cond.cleanup:523; CHECK-NEXT: ret void524; CHECK: for.body:525; CHECK-NEXT: [[I_011:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]526; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[COND]], i32 [[I_011]]527; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr [[ARRAYIDX]], align 4528; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[TMP9]], 0529; CHECK-NEXT: [[C_B:%.*]] = select i1 [[TOBOOL_NOT]], ptr [[C]], ptr [[B]]530; CHECK-NEXT: [[COND_IN:%.*]] = getelementptr inbounds i32, ptr [[C_B]], i32 [[I_011]]531; CHECK-NEXT: [[COND:%.*]] = load i32, ptr [[COND_IN]], align 4532; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[I_011]]533; CHECK-NEXT: store i32 [[COND]], ptr [[ARRAYIDX3]], align 4534; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_011]], 1535; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i32 [[INC]], [[N]]536; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP15:![0-9]+]]537;538entry:539 %cmp10 = icmp sgt i32 %N, 0540 br i1 %cmp10, label %for.body.preheader, label %for.cond.cleanup541 542for.body.preheader: ; preds = %entry543 br label %for.body544 545for.cond.cleanup.loopexit: ; preds = %for.body546 br label %for.cond.cleanup547 548for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry549 ret void550 551for.body: ; preds = %for.body.preheader, %for.body552 %i.011 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]553 %arrayidx = getelementptr inbounds i32, ptr %Cond, i32 %i.011554 %0 = load i32, ptr %arrayidx, align 4555 %tobool.not = icmp eq i32 %0, 0556 %C.B = select i1 %tobool.not, ptr %C, ptr %B557 %cond.in = getelementptr inbounds i32, ptr %C.B, i32 %i.011558 %cond = load i32, ptr %cond.in, align 4559 %arrayidx3 = getelementptr inbounds i32, ptr %A, i32 %i.011560 store i32 %cond, ptr %arrayidx3, align 4561 %inc = add nuw nsw i32 %i.011, 1562 %exitcond.not = icmp eq i32 %inc, %N563 br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body564}565 566define i32 @i32_smin_reduction(ptr nocapture readonly %x, i32 %n) #0 {567; CHECK-LABEL: @i32_smin_reduction(568; CHECK-NEXT: entry:569; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0570; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]571; CHECK: for.body.preheader:572; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4573; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]574; CHECK: vector.ph:575; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4576; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]577; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]578; CHECK: vector.body:579; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]580; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ splat (i32 2147483647), [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]581; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[X:%.*]], i32 [[INDEX]]582; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4583; CHECK-NEXT: [[TMP3:%.*]] = icmp slt <4 x i32> [[VEC_PHI]], [[WIDE_LOAD]]584; CHECK-NEXT: [[TMP4]] = select <4 x i1> [[TMP3]], <4 x i32> [[VEC_PHI]], <4 x i32> [[WIDE_LOAD]]585; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4586; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]587; CHECK-NEXT: br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP16:![0-9]+]]588; CHECK: middle.block:589; CHECK-NEXT: [[TMP6:%.*]] = call i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> [[TMP4]])590; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]591; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]592; CHECK: scalar.ph:593; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ]594; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP6]], [[MIDDLE_BLOCK]] ], [ 2147483647, [[FOR_BODY_PREHEADER]] ]595; CHECK-NEXT: br label [[FOR_BODY:%.*]]596; CHECK: for.body:597; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]598; CHECK-NEXT: [[R_07:%.*]] = phi i32 [ [[ADD:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]599; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[X]], i32 [[I_08]]600; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX]], align 4601; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[R_07]], [[TMP7]]602; CHECK-NEXT: [[ADD]] = select i1 [[C]], i32 [[R_07]], i32 [[TMP7]]603; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1604; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[N]]605; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]606; CHECK: for.cond.cleanup.loopexit:607; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i32 [ [[ADD]], [[FOR_BODY]] ], [ [[TMP6]], [[MIDDLE_BLOCK]] ]608; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]609; CHECK: for.cond.cleanup:610; CHECK-NEXT: [[R_0_LCSSA:%.*]] = phi i32 [ 2147483647, [[ENTRY:%.*]] ], [ [[ADD_LCSSA]], [[FOR_COND_CLEANUP_LOOPEXIT]] ]611; CHECK-NEXT: ret i32 [[R_0_LCSSA]]612;613entry:614 %cmp6 = icmp sgt i32 %n, 0615 br i1 %cmp6, label %for.body, label %for.cond.cleanup616 617for.body: ; preds = %entry, %for.body618 %i.08 = phi i32 [ %inc, %for.body ], [ 0, %entry ]619 %r.07 = phi i32 [ %add, %for.body ], [ 2147483647, %entry ]620 %arrayidx = getelementptr inbounds i32, ptr %x, i32 %i.08621 %0 = load i32, ptr %arrayidx, align 4622 %c = icmp slt i32 %r.07, %0623 %add = select i1 %c, i32 %r.07, i32 %0624 %inc = add nuw nsw i32 %i.08, 1625 %exitcond = icmp eq i32 %inc, %n626 br i1 %exitcond, label %for.cond.cleanup, label %for.body627 628for.cond.cleanup: ; preds = %for.body, %entry629 %r.0.lcssa = phi i32 [ 2147483647, %entry ], [ %add, %for.body ]630 ret i32 %r.0.lcssa631}632 633define i32 @i32_smax_reduction(ptr nocapture readonly %x, i32 %n) #0 {634; CHECK-LABEL: @i32_smax_reduction(635; CHECK-NEXT: entry:636; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0637; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]638; CHECK: for.body.preheader:639; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4640; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]641; CHECK: vector.ph:642; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4643; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]644; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]645; CHECK: vector.body:646; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]647; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ splat (i32 -2147483648), [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]648; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[X:%.*]], i32 [[INDEX]]649; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4650; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt <4 x i32> [[VEC_PHI]], [[WIDE_LOAD]]651; CHECK-NEXT: [[TMP4]] = select <4 x i1> [[TMP3]], <4 x i32> [[VEC_PHI]], <4 x i32> [[WIDE_LOAD]]652; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4653; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]654; CHECK-NEXT: br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]655; CHECK: middle.block:656; CHECK-NEXT: [[TMP6:%.*]] = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> [[TMP4]])657; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]658; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]659; CHECK: scalar.ph:660; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ]661; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP6]], [[MIDDLE_BLOCK]] ], [ -2147483648, [[FOR_BODY_PREHEADER]] ]662; CHECK-NEXT: br label [[FOR_BODY:%.*]]663; CHECK: for.body:664; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]665; CHECK-NEXT: [[R_07:%.*]] = phi i32 [ [[ADD:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]666; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[X]], i32 [[I_08]]667; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX]], align 4668; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[R_07]], [[TMP7]]669; CHECK-NEXT: [[ADD]] = select i1 [[C]], i32 [[R_07]], i32 [[TMP7]]670; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1671; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[N]]672; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]673; CHECK: for.cond.cleanup.loopexit:674; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i32 [ [[ADD]], [[FOR_BODY]] ], [ [[TMP6]], [[MIDDLE_BLOCK]] ]675; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]676; CHECK: for.cond.cleanup:677; CHECK-NEXT: [[R_0_LCSSA:%.*]] = phi i32 [ -2147483648, [[ENTRY:%.*]] ], [ [[ADD_LCSSA]], [[FOR_COND_CLEANUP_LOOPEXIT]] ]678; CHECK-NEXT: ret i32 [[R_0_LCSSA]]679;680entry:681 %cmp6 = icmp sgt i32 %n, 0682 br i1 %cmp6, label %for.body, label %for.cond.cleanup683 684for.body: ; preds = %entry, %for.body685 %i.08 = phi i32 [ %inc, %for.body ], [ 0, %entry ]686 %r.07 = phi i32 [ %add, %for.body ], [ -2147483648, %entry ]687 %arrayidx = getelementptr inbounds i32, ptr %x, i32 %i.08688 %0 = load i32, ptr %arrayidx, align 4689 %c = icmp sgt i32 %r.07, %0690 %add = select i1 %c, i32 %r.07, i32 %0691 %inc = add nuw nsw i32 %i.08, 1692 %exitcond = icmp eq i32 %inc, %n693 br i1 %exitcond, label %for.cond.cleanup, label %for.body694 695for.cond.cleanup: ; preds = %for.body, %entry696 %r.0.lcssa = phi i32 [ -2147483648, %entry ], [ %add, %for.body ]697 ret i32 %r.0.lcssa698}699 700define i32 @i32_umin_reduction(ptr nocapture readonly %x, i32 %n) #0 {701; CHECK-LABEL: @i32_umin_reduction(702; CHECK-NEXT: entry:703; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0704; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]705; CHECK: for.body.preheader:706; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4707; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]708; CHECK: vector.ph:709; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4710; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]711; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]712; CHECK: vector.body:713; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]714; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ splat (i32 -1), [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]715; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[X:%.*]], i32 [[INDEX]]716; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4717; CHECK-NEXT: [[TMP3:%.*]] = icmp ult <4 x i32> [[VEC_PHI]], [[WIDE_LOAD]]718; CHECK-NEXT: [[TMP4]] = select <4 x i1> [[TMP3]], <4 x i32> [[VEC_PHI]], <4 x i32> [[WIDE_LOAD]]719; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4720; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]721; CHECK-NEXT: br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP20:![0-9]+]]722; CHECK: middle.block:723; CHECK-NEXT: [[TMP6:%.*]] = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> [[TMP4]])724; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]725; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]726; CHECK: scalar.ph:727; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ]728; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP6]], [[MIDDLE_BLOCK]] ], [ -1, [[FOR_BODY_PREHEADER]] ]729; CHECK-NEXT: br label [[FOR_BODY:%.*]]730; CHECK: for.body:731; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]732; CHECK-NEXT: [[R_07:%.*]] = phi i32 [ [[ADD:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]733; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[X]], i32 [[I_08]]734; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX]], align 4735; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[R_07]], [[TMP7]]736; CHECK-NEXT: [[ADD]] = select i1 [[C]], i32 [[R_07]], i32 [[TMP7]]737; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1738; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[N]]739; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP21:![0-9]+]]740; CHECK: for.cond.cleanup.loopexit:741; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i32 [ [[ADD]], [[FOR_BODY]] ], [ [[TMP6]], [[MIDDLE_BLOCK]] ]742; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]743; CHECK: for.cond.cleanup:744; CHECK-NEXT: [[R_0_LCSSA:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[ADD_LCSSA]], [[FOR_COND_CLEANUP_LOOPEXIT]] ]745; CHECK-NEXT: ret i32 [[R_0_LCSSA]]746;747entry:748 %cmp6 = icmp sgt i32 %n, 0749 br i1 %cmp6, label %for.body, label %for.cond.cleanup750 751for.body: ; preds = %entry, %for.body752 %i.08 = phi i32 [ %inc, %for.body ], [ 0, %entry ]753 %r.07 = phi i32 [ %add, %for.body ], [ 4294967295, %entry ]754 %arrayidx = getelementptr inbounds i32, ptr %x, i32 %i.08755 %0 = load i32, ptr %arrayidx, align 4756 %c = icmp ult i32 %r.07, %0757 %add = select i1 %c, i32 %r.07, i32 %0758 %inc = add nuw nsw i32 %i.08, 1759 %exitcond = icmp eq i32 %inc, %n760 br i1 %exitcond, label %for.cond.cleanup, label %for.body761 762for.cond.cleanup: ; preds = %for.body, %entry763 %r.0.lcssa = phi i32 [ 4294967295, %entry ], [ %add, %for.body ]764 ret i32 %r.0.lcssa765}766 767define i32 @i32_umax_reduction(ptr nocapture readonly %x, i32 %n) #0 {768; CHECK-LABEL: @i32_umax_reduction(769; CHECK-NEXT: entry:770; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0771; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]772; CHECK: for.body.preheader:773; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4774; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]775; CHECK: vector.ph:776; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4777; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]778; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]779; CHECK: vector.body:780; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]781; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]782; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[X:%.*]], i32 [[INDEX]]783; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP1]], align 4784; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt <4 x i32> [[VEC_PHI]], [[WIDE_LOAD]]785; CHECK-NEXT: [[TMP4]] = select <4 x i1> [[TMP3]], <4 x i32> [[VEC_PHI]], <4 x i32> [[WIDE_LOAD]]786; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4787; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]788; CHECK-NEXT: br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]789; CHECK: middle.block:790; CHECK-NEXT: [[TMP6:%.*]] = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> [[TMP4]])791; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]792; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]793; CHECK: scalar.ph:794; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ]795; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[TMP6]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ]796; CHECK-NEXT: br label [[FOR_BODY:%.*]]797; CHECK: for.body:798; CHECK-NEXT: [[I_08:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]799; CHECK-NEXT: [[R_07:%.*]] = phi i32 [ [[ADD:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]800; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[X]], i32 [[I_08]]801; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[ARRAYIDX]], align 4802; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[R_07]], [[TMP7]]803; CHECK-NEXT: [[ADD]] = select i1 [[C]], i32 [[R_07]], i32 [[TMP7]]804; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[I_08]], 1805; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[N]]806; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]807; CHECK: for.cond.cleanup.loopexit:808; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i32 [ [[ADD]], [[FOR_BODY]] ], [ [[TMP6]], [[MIDDLE_BLOCK]] ]809; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]810; CHECK: for.cond.cleanup:811; CHECK-NEXT: [[R_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[ADD_LCSSA]], [[FOR_COND_CLEANUP_LOOPEXIT]] ]812; CHECK-NEXT: ret i32 [[R_0_LCSSA]]813;814entry:815 %cmp6 = icmp sgt i32 %n, 0816 br i1 %cmp6, label %for.body, label %for.cond.cleanup817 818for.body: ; preds = %entry, %for.body819 %i.08 = phi i32 [ %inc, %for.body ], [ 0, %entry ]820 %r.07 = phi i32 [ %add, %for.body ], [ 0, %entry ]821 %arrayidx = getelementptr inbounds i32, ptr %x, i32 %i.08822 %0 = load i32, ptr %arrayidx, align 4823 %c = icmp ugt i32 %r.07, %0824 %add = select i1 %c, i32 %r.07, i32 %0825 %inc = add nuw nsw i32 %i.08, 1826 %exitcond = icmp eq i32 %inc, %n827 br i1 %exitcond, label %for.cond.cleanup, label %for.body828 829for.cond.cleanup: ; preds = %for.body, %entry830 %r.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]831 ret i32 %r.0.lcssa832}833 834!10 = distinct !{!10, !11}835!11 = !{!"llvm.loop.vectorize.width", i32 4}836