Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -3586,8 +3586,12 @@ IRBuilder<> B(MiddleBlock->getTerminator()); Value *CountMinusOne = B.CreateSub( CountRoundDown, ConstantInt::get(CountRoundDown->getType(), 1)); - Value *CMO = B.CreateSExtOrTrunc(CountMinusOne, II.getStep()->getType(), - "cast.cmo"); + Value *CMO = + !II.getStep()->getType()->isIntegerTy() + ? B.CreateCast(Instruction::SIToFP, CountMinusOne, + II.getStep()->getType()) + : B.CreateSExtOrTrunc(CountMinusOne, II.getStep()->getType()); + CMO->setName("cast.cmo"); Value *Escape = II.transform(B, CMO, PSE.getSE(), DL); Escape->setName("ind.escape"); MissingVals[UI] = Escape; Index: test/Transforms/LoopVectorize/float-induction.ll =================================================================== --- test/Transforms/LoopVectorize/float-induction.ll +++ test/Transforms/LoopVectorize/float-induction.ll @@ -338,3 +338,44 @@ for.end: ret void } + +; VEC4_INTERL1-LABEL: @external_use( +; VEC4_INTERL1-NEXT: entry: +; VEC4_INTERL1-NEXT: [[TMP0:%.*]] = icmp sgt i64 %n, 1 +; VEC4_INTERL1-NEXT: [[SMAX:%.*]] = select i1 [[TMP0]], i64 %n, i64 1 +; VEC4_INTERL1: br i1 {{.*}}, label %scalar.ph, label %min.iters.checked +; VEC4_INTERL1: min.iters.checked: +; VEC4_INTERL1-NEXT: [[N_VEC:%.*]] = and i64 [[SMAX]], 9223372036854775804 +; VEC4_INTERL1: br i1 {{.*}}, label %scalar.ph, label %vector.ph +; VEC4_INTERL1: vector.ph: +; VEC4_INTERL1-NEXT: br label %vector.body +; VEC4_INTERL1: vector.body: +; VEC4_INTERL1-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ] +; VEC4_INTERL1-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4 +; VEC4_INTERL1-NEXT: [[TMP1:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] +; VEC4_INTERL1-NEXT: br i1 [[TMP1]], label %middle.block, label %vector.body +; VEC4_INTERL1: middle.block: +; VEC4_INTERL1: [[TMP2:%.*]] = add nsw i64 [[N_VEC]], -1 +; VEC4_INTERL1-NEXT: [[CAST_CMO:%.*]] = sitofp i64 [[TMP2]] to double +; VEC4_INTERL1-NEXT: [[IND_ESCAPE:%.*]] = fadd fast double [[CAST_CMO]], %m +; VEC4_INTERL1-NEXT: br i1 {{.*}}, label %for.end, label %scalar.ph +; VEC4_INTERL1: for.end: +; VEC4_INTERL1-NEXT: [[TMP0:%.*]] = phi double [ %j, %for.body ], [ [[IND_ESCAPE]], %middle.block ] +; VEC4_INTERL1-NEXT: ret double [[TMP0]] + +define double @external_use(double %m, i64 %n) { +entry: + br label %for.body + +for.body: + %i = phi i64 [ 0, %entry ], [%i.next, %for.body] + %j = phi double [ %m, %entry ], [ %j.next, %for.body ] + %i.next = add i64 %i, 1 + %j.next = fadd fast double %j, 1.0 + %cond = icmp slt i64 %i.next, %n + br i1 %cond, label %for.body, label %for.end + +for.end: + %tmp0 = phi double [ %j, %for.body ] + ret double %tmp0 +}