1; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -S < %s | FileCheck %s --check-prefix=CHECK-VF2IC1 2; RUN: opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -S < %s | FileCheck %s --check-prefix=CHECK-VF1IC2 3 4define i32 @pred_select_const_i32_from_icmp(ptr noalias nocapture readonly %src1, ptr noalias nocapture readonly %src2, i64 %n) { 5; CHECK-VF2IC1-LABEL: @pred_select_const_i32_from_icmp( 6; CHECK-VF2IC1: vector.body: 7; CHECK-VF2IC1: [[VEC_PHI:%.*]] = phi <2 x i1> [ zeroinitializer, %vector.ph ], [ [[PREDPHI:%.*]], %pred.load.continue2 ] 8; CHECK-VF2IC1: [[WIDE_LOAD:%.*]] = load <2 x i32>, ptr {{%.*}}, align 4 9; CHECK-VF2IC1-NEXT: [[TMP4:%.*]] = icmp sgt <2 x i32> [[WIDE_LOAD]], splat (i32 35) 10; CHECK-VF2IC1-NEXT: [[TMP5:%.*]] = extractelement <2 x i1> [[TMP4]], i32 0 11; CHECK-VF2IC1-NEXT: br i1 [[TMP5]], label %pred.load.if, label %pred.load.continue 12; CHECK-VF2IC1: pred.load.if: 13; CHECK-VF2IC1-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[SRC2:%.*]], i64 {{%.*}} 14; CHECK-VF2IC1-NEXT: [[TMP7:%.*]] = load i32, ptr [[TMP6]], align 4 15; CHECK-VF2IC1-NEXT: [[TMP8:%.*]] = insertelement <2 x i32> poison, i32 [[TMP7]], i32 0 16; CHECK-VF2IC1-NEXT: br label %pred.load.continue 17; CHECK-VF2IC1: pred.load.continue: 18; CHECK-VF2IC1-NEXT: [[TMP9:%.*]] = phi <2 x i32> [ poison, %vector.body ], [ [[TMP8]], %pred.load.if ] 19; CHECK-VF2IC1-NEXT: [[TMP10:%.*]] = extractelement <2 x i1> [[TMP4]], i32 1 20; CHECK-VF2IC1-NEXT: br i1 [[TMP10]], label %pred.load.if1, label %pred.load.continue2 21; CHECK-VF2IC1: pred.load.if1: 22; CHECK-VF2IC1: [[TMP12:%.*]] = getelementptr inbounds i32, ptr [[SRC2]], i64 {{%.*}} 23; CHECK-VF2IC1-NEXT: [[TMP13:%.*]] = load i32, ptr [[TMP12]], align 4 24; CHECK-VF2IC1-NEXT: [[TMP14:%.*]] = insertelement <2 x i32> [[TMP9]], i32 [[TMP13]], i32 1 25; CHECK-VF2IC1-NEXT: br label %pred.load.continue2 26; CHECK-VF2IC1: pred.load.continue2: 27; CHECK-VF2IC1-NEXT: [[TMP15:%.*]] = phi <2 x i32> [ [[TMP9]], %pred.load.continue ], [ [[TMP14]], %pred.load.if1 ] 28; CHECK-VF2IC1-NEXT: [[TMP16:%.*]] = icmp eq <2 x i32> [[TMP15]], splat (i32 2) 29; CHECK-VF2IC1-NEXT: [[TMP17:%.*]] = or <2 x i1> [[VEC_PHI]], [[TMP16]] 30; CHECK-VF2IC1-NEXT: [[PREDPHI]] = select <2 x i1> [[TMP4]], <2 x i1> [[TMP17]], <2 x i1> [[VEC_PHI]] 31; CHECK-VF2IC1: br i1 {{%.*}}, label %middle.block, label %vector.body 32; CHECK-VF2IC1: middle.block: 33; CHECK-VF2IC1-NEXT: [[TMP20:%.*]] = call i1 @llvm.vector.reduce.or.v2i1(<2 x i1> [[PREDPHI]]) 34; CHECK-VF2IC1-NEXT: [[FR_TMP20:%.*]] = freeze i1 [[TMP20]] 35; CHECK-VF2IC1-NEXT: [[RDX_SELECT:%.*]] = select i1 [[FR_TMP20]], i32 1, i32 0 36; CHECK-VF2IC1-NEXT: %cmp.n = icmp eq i64 %n, %n.vec 37; CHECK-VF2IC1: scalar.ph: 38; CHECK-VF2IC1: [[BC_RESUME_VAL:%.*]] = phi i64 [ {{%.*}}, %middle.block ], [ 0, %entry ] 39; CHECK-VF2IC1-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[RDX_SELECT]], %middle.block ], [ 0, %entry ] 40; CHECK-VF2IC1-NEXT: br label %for.body 41; CHECK-VF2IC1: for.body: 42; CHECK-VF2IC1: [[R_012:%.*]] = phi i32 [ [[R_1:%.*]], %for.inc ], [ [[BC_MERGE_RDX]], %scalar.ph ] 43; CHECK-VF2IC1: [[TMP21:%.*]] = load i32, ptr {{%.*}}, align 4 44; CHECK-VF2IC1-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[TMP21]], 35 45; CHECK-VF2IC1-NEXT: br i1 [[CMP1]], label %if.then, label %for.inc 46; CHECK-VF2IC1: if.then: 47; CHECK-VF2IC1: [[TMP22:%.*]] = load i32, ptr {{%.*}}, align 4 48; CHECK-VF2IC1-NEXT: [[CMP3:%.*]] = icmp eq i32 [[TMP22]], 2 49; CHECK-VF2IC1-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[CMP3]], i32 1, i32 [[R_012]] 50; CHECK-VF2IC1-NEXT: br label %for.inc 51; CHECK-VF2IC1: for.inc: 52; CHECK-VF2IC1-NEXT: [[R_1]] = phi i32 [ [[R_012]], %for.body ], [ [[SPEC_SELECT]], %if.then ] 53; CHECK-VF2IC1: for.end.loopexit: 54; CHECK-VF2IC1-NEXT: [[R_1_LCSSA:%.*]] = phi i32 [ [[R_1]], %for.inc ], [ [[RDX_SELECT]], %middle.block ] 55; CHECK-VF2IC1-NEXT: ret i32 [[R_1_LCSSA]] 56; 57; CHECK-VF1IC2-LABEL: @pred_select_const_i32_from_icmp( 58; CHECK-VF1IC2: vector.body: 59; CHECK-VF1IC2: [[VEC_PHI:%.*]] = phi i1 [ false, %vector.ph ], [ [[PREDPHI:%.*]], %pred.load.continue3 ] 60; CHECK-VF1IC2-NEXT: [[VEC_PHI2:%.*]] = phi i1 [ false, %vector.ph ], [ [[PREDPHI5:%.*]], %pred.load.continue3 ] 61; CHECK-VF1IC2: [[TMP0:%.*]] = getelementptr inbounds i32, ptr [[SRC1:%.*]], i64 {{%.*}} 62; CHECK-VF1IC2-NEXT: [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[SRC1]], i64 {{%.*}} 63; CHECK-VF1IC2-NEXT: [[TMP2:%.*]] = load i32, ptr [[TMP0]], align 4 64; CHECK-VF1IC2-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP1]], align 4 65; CHECK-VF1IC2-NEXT: [[TMP4:%.*]] = icmp sgt i32 [[TMP2]], 35 66; CHECK-VF1IC2-NEXT: [[TMP5:%.*]] = icmp sgt i32 [[TMP3]], 35 67; CHECK-VF1IC2-NEXT: br i1 [[TMP4]], label %pred.load.if, label %pred.load.continue 68; CHECK-VF1IC2: pred.load.if: 69; CHECK-VF1IC2-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[SRC2:%.*]], i64 {{%.*}} 70; CHECK-VF1IC2-NEXT: [[TMP7:%.*]] = load i32, ptr [[TMP6]], align 4 71; CHECK-VF1IC2-NEXT: br label %pred.load.continue 72; CHECK-VF1IC2: pred.load.continue: 73; CHECK-VF1IC2-NEXT: [[TMP8:%.*]] = phi i32 [ poison, %vector.body ], [ [[TMP7]], %pred.load.if ] 74; CHECK-VF1IC2-NEXT: br i1 [[TMP5]], label %pred.load.if2, label %pred.load.continue3 75; CHECK-VF1IC2: pred.load.if2: 76; CHECK-VF1IC2-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[SRC2]], i64 {{%.*}} 77; CHECK-VF1IC2-NEXT: [[TMP10:%.*]] = load i32, ptr [[TMP9]], align 4 78; CHECK-VF1IC2-NEXT: br label %pred.load.continue3 79; CHECK-VF1IC2: pred.load.continue3: 80; CHECK-VF1IC2-NEXT: [[TMP11:%.*]] = phi i32 [ poison, %pred.load.continue ], [ [[TMP10]], %pred.load.if2 ] 81; CHECK-VF1IC2-NEXT: [[TMP12:%.*]] = icmp eq i32 [[TMP8]], 2 82; CHECK-VF1IC2-NEXT: [[TMP13:%.*]] = icmp eq i32 [[TMP11]], 2 83; CHECK-VF1IC2-NEXT: [[TMP14:%.*]] = or i1 [[VEC_PHI]], [[TMP12]] 84; CHECK-VF1IC2-NEXT: [[TMP15:%.*]] = or i1 [[VEC_PHI2]], [[TMP13]] 85; CHECK-VF1IC2-NEXT: [[PREDPHI]] = select i1 [[TMP4]], i1 [[TMP14]], i1 [[VEC_PHI]] 86; CHECK-VF1IC2-NEXT: [[PREDPHI5]] = select i1 [[TMP5]], i1 [[TMP15]], i1 [[VEC_PHI2]] 87; CHECK-VF1IC2: br i1 {{%.*}}, label %middle.block, label %vector.body 88; CHECK-VF1IC2: middle.block: 89; CHECK-VF1IC2-NEXT: [[OR:%.*]] = or i1 [[PREDPHI5]], [[PREDPHI]] 90; CHECK-VF1IC2-NEXT: [[FR_OR:%.*]] = freeze i1 [[OR]] 91; CHECK-VF1IC2-NEXT: [[RDX_SELECT:%.*]] = select i1 [[FR_OR]], i32 1, i32 0 92; CHECK-VF1IC2-NEXT: %cmp.n = icmp eq i64 %n, %n.vec 93; CHECK-VF1IC2: br i1 %cmp.n, label %for.end.loopexit, label %scalar.ph 94; CHECK-VF1IC2: scalar.ph: 95; CHECK-VF1IC2-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ {{%.*}}, %middle.block ], [ 0, %entry ] 96; CHECK-VF1IC2-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ [[RDX_SELECT]], %middle.block ], [ 0, %entry ] 97; CHECK-VF1IC2-NEXT: br label %for.body 98; CHECK-VF1IC2: for.body: 99; CHECK-VF1IC2-NEXT: [[I_013:%.*]] = phi i64 [ [[INC:%.*]], %for.inc ], [ [[BC_RESUME_VAL]], %scalar.ph ] 100; CHECK-VF1IC2-NEXT: [[R_012:%.*]] = phi i32 [ [[R_1:%.*]], %for.inc ], [ [[BC_MERGE_RDX]], %scalar.ph ] 101; CHECK-VF1IC2: [[TMP19:%.*]] = load i32, ptr {{%.*}}, align 4 102; CHECK-VF1IC2-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[TMP19]], 35 103; CHECK-VF1IC2-NEXT: br i1 [[CMP1]], label [[IF_THEN:%.*]], label %for.inc 104; CHECK-VF1IC2: if.then: 105; CHECK-VF1IC2: [[TMP20:%.*]] = load i32, ptr {{%.*}}, align 4 106; CHECK-VF1IC2-NEXT: [[CMP3:%.*]] = icmp eq i32 [[TMP20]], 2 107; CHECK-VF1IC2-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[CMP3]], i32 1, i32 [[R_012]] 108; CHECK-VF1IC2-NEXT: br label %for.inc 109; CHECK-VF1IC2: for.inc: 110; CHECK-VF1IC2-NEXT: [[R_1]] = phi i32 [ [[R_012]], %for.body ], [ [[SPEC_SELECT]], %if.then ] 111; CHECK-VF1IC2: br i1 {{%.*}}, label %for.end.loopexit, label %for.body 112; CHECK-VF1IC2: for.end.loopexit: 113; CHECK-VF1IC2-NEXT: [[R_1_LCSSA:%.*]] = phi i32 [ [[R_1]], %for.inc ], [ [[RDX_SELECT]], %middle.block ] 114; CHECK-VF1IC2-NEXT: ret i32 [[R_1_LCSSA]] 115; 116entry: 117 br label %for.body 118 119for.body: ; preds = %entry, %for.inc 120 %i.013 = phi i64 [ %inc, %for.inc ], [ 0, %entry ] 121 %r.012 = phi i32 [ %r.1, %for.inc ], [ 0, %entry ] 122 %arrayidx = getelementptr inbounds i32, ptr %src1, i64 %i.013 123 %0 = load i32, ptr %arrayidx, align 4 124 %cmp1 = icmp sgt i32 %0, 35 125 br i1 %cmp1, label %if.then, label %for.inc 126 127if.then: ; preds = %for.body 128 %arrayidx2 = getelementptr inbounds i32, ptr %src2, i64 %i.013 129 %1 = load i32, ptr %arrayidx2, align 4 130 %cmp3 = icmp eq i32 %1, 2 131 %spec.select = select i1 %cmp3, i32 1, i32 %r.012 132 br label %for.inc 133 134for.inc: ; preds = %if.then, %for.body 135 %r.1 = phi i32 [ %r.012, %for.body ], [ %spec.select, %if.then ] 136 %inc = add nuw nsw i64 %i.013, 1 137 %exitcond.not = icmp eq i64 %inc, %n 138 br i1 %exitcond.not, label %for.end.loopexit, label %for.body 139 140for.end.loopexit: ; preds = %for.inc 141 %r.1.lcssa = phi i32 [ %r.1, %for.inc ] 142 ret i32 %r.1.lcssa 143} 144