Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4730,6 +4730,16 @@ } } + // When the first operand of a bitcast instruction is of vector type, its + // vector operand must be loop-invariant and the bitcast must be uniform. + if (isa(&I) && I.getOperand(0)->getType()->isVectorTy()) { + assert(TheLoop->hasLoopInvariantOperands(&I) && + "Vector operand must be loop-invariant"); + LLVM_DEBUG(dbgs() << "LV: Found uniform instruction: " << I << "\n"); + addToWorklistIfAllowed(&I); + continue; + } + // ExtractValue instructions must be uniform, because the operands are // known to be loop-invariant. if (auto *EVI = dyn_cast(&I)) { Index: llvm/test/Transforms/LoopVectorize/vector2scalar-bitcast.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LoopVectorize/vector2scalar-bitcast.ll @@ -0,0 +1,30 @@ +; REQUIRES: assert +; RUN: opt < %s -loop-vectorize -force-vector-width=2 -S 2>&1 | FileCheck %s + +; Function Attrs: argmemonly nofree norecurse nosync nounwind uwtable +define dso_local i64 @foo(ptr nocapture noundef %a, i32 noundef %n, <2 x float> %in2) { +entry: + %cmp3 = icmp sgt i32 %n, 0 + br i1 %cmp3, label %for.body.preheader, label %for.cond.cleanup + +for.body.preheader: ; preds = %entry + %wide.trip.count = zext i32 %n to i64 + br label %for.body + +for.cond.cleanup: ; preds = %for.body, %entry + %result = phi i64 [ 0, %entry], [ %illegal, %for.body] + ret i64 %result + +for.body: ; preds = %for.body.preheader, %for.body + %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ] + %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv + %illegal = bitcast <2 x float> %in2 to i64 + %0 = load i32, ptr %arrayidx, align 4 + %add = add nsw i32 %0, 1 + store i32 %add, ptr %arrayidx, align 4 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count + br i1 %exitcond.not, label %for.cond.cleanup, label %for.body +} + +