Bug type: crash
Component: LoopVectorize
Bug location: llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp: VPTypeAnalysis::inferScalarTypeForRecipe
Issue title: [Loop Vectorizer] Unhandled opcode UNREACHABLE executed at llvm/llvm-project/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp:208!
Labels: vectorizers
crash
Reported by: wenju-he

```
opt -passes=loop-vectorize before-loop-vectorize.ll

Unhandled opcode
UNREACHABLE executed at /llvm/llvm-project/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp:208!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /llvm/llvm-project/build/bin/opt -passes=loop-vectorize before-loop-vectorize.ll
 #0 0x0000000003167161 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/llvm/llvm-project/build/bin/opt+0x3167161)
 #1 0x00000000031646c4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fcb77b7bdb0 __restore_rt (/lib64/libc.so.6+0x59db0)
 #3 0x00007fcb77bc842c __pthread_kill_implementation (/lib64/libc.so.6+0xa642c)
 #4 0x00007fcb77b7bd06 gsignal (/lib64/libc.so.6+0x59d06)
 #5 0x00007fcb77b4e7d3 abort (/lib64/libc.so.6+0x2c7d3)
 #6 0x00000000030ac16a (/llvm/llvm-project/build/bin/opt+0x30ac16a)
 #7 0x00000000022ffc8d llvm::VPTypeAnalysis::inferScalarTypeForRecipe(llvm::VPReplicateRecipe const*) (/llvm/llvm-project/build/bin/opt+0x22ffc8d)
 #8 0x00000000022ff04c llvm::VPTypeAnalysis::inferScalarType(llvm::VPValue const*) (/llvm/llvm-project/build/bin/opt+0x22ff04c)
 #9 0x00000000021cb7f4 llvm::InnerLoopVectorizer::scalarizeInstruction(llvm::Instruction const*, llvm::VPReplicateRecipe*, llvm::VPIteration const&, llvm::VPTransformState&) (/llvm/llvm-project/build/bin/opt+0x21cb7f4)
#10 0x00000000021cecb5 llvm::VPReplicateRecipe::execute(llvm::VPTransformState&) (/llvm/llvm-project/build/bin/opt+0x21cecb5)
#11 0x00000000022f834f llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22f834f)
#12 0x00000000022f0130 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22f0130)
#13 0x00000000022f03d8 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22f03d8)
#14 0x00000000022fb806 llvm::VPlan::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22fb806)
#15 0x00000000021e983b llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/llvm/llvm-project/build/bin/opt+0x21e983b)
#16 0x00000000021fbbe0 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/llvm/llvm-project/build/bin/opt+0x21fbbe0)
#17 0x00000000021fde5e llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/llvm/llvm-project/build/bin/opt+0x21fde5e)
#18 0x00000000021fef78 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x21fef78)
#19 0x0000000001125c8e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x1125c8e)
#20 0x0000000002f8671a llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x2f8671a)
#21 0x000000000082c95e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x82c95e)
#22 0x0000000002f853cd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/llvm/llvm-project/build/bin/opt+0x2f853cd)
#23 0x000000000082da6e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/llvm/llvm-project/build/bin/opt+0x82da6e)
#24 0x0000000002f832cc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/llvm/llvm-project/build/bin/opt+0x2f832cc)
#25 0x00000000007a0d5d llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/llvm/llvm-project/build/bin/opt+0x7a0d5d)
#26 0x0000000000793a7c optMain (/llvm/llvm-project/build/bin/opt+0x793a7c)
#27 0x00007fcb77b66e50 __libc_start_call_main (/lib64/libc.so.6+0x44e50)
#28 0x00007fcb77b66efc __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x44efc)
#29 0x0000000000789e15 _start (/llvm/llvm-project/build/bin/opt+0x789e15)
Aborted (core dumped)
```
Input IR file before-loop-vectorize.ll is:
```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.sycl::_V1::range" = type { %"class.sycl::_V1::detail::array" }
%"class.sycl::_V1::detail::array" = type { [1 x i64] }

$_ZTSN4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EE = comdat any

$_ZTSZZ12foo_parallelRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlNS0_2idILi1EEEE_ = comdat any

$_ZTSZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlvE_ = comdat any

; Function Attrs: convergent norecurse nounwind
define weak_odr dso_local spir_kernel void @_ZTSN4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EE(ptr noundef byval(%"class.sycl::_V1::range") align 8 %_arg_UserRange, ptr addrspace(1) noundef align 4 %_arg_acc, ptr noundef byval(%"class.sycl::_V1::range") align 8 %_arg_acc3) local_unnamed_addr #0 comdat !srcloc !7 !kernel_arg_buffer_location !8 !kernel_arg_runtime_aligned !9 !kernel_arg_exclusive_ptr !9 !sycl_fixed_targets !10 !sycl_kernel_omit_args !11 {
entry:
  %0 = load i64, ptr %_arg_UserRange, align 8
  %agg.tmp7.sroa.0.0.copyload = load i64, ptr %_arg_acc3, align 8
  %add.ptr.i = getelementptr inbounds float, ptr addrspace(1) %_arg_acc, i64 %agg.tmp7.sroa.0.0.copyload
  %call.i = tail call i64 @_Z21__spirv_WorkgroupId_xv() #5, !noalias !12
  %call1.i = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !12
  %mul.i = mul i64 %call1.i, %call.i
  %call2.i = tail call i64 @_Z27__spirv_LocalInvocationId_xv() #5, !noalias !12
  %add.i = add i64 %mul.i, %call2.i
  %call3.i = tail call i64 @_Z22__spirv_GlobalOffset_xv() #5, !noalias !12
  %add4.i = add i64 %add.i, %call3.i
  %call.i1 = tail call i64 @_Z23__spirv_NumWorkgroups_xv() #5, !noalias !12
  %call1.i2 = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !12
  %mul.i3 = mul i64 %call1.i2, %call.i1
  %call.i.i.i9.i.i = tail call noundef i64 @_Z22__spirv_GlobalOffset_xv() #6, !noalias !12
  %cmp6.not.i.not.i = icmp ult i64 %add4.i, %0
  br i1 %cmp6.not.i.not.i, label %for.body.i.preheader, label %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit

for.body.i.preheader:                             ; preds = %entry
  br label %for.body.i

for.body.i:                                       ; preds = %for.body.i.preheader, %for.body.i
  %Gen.sroa.0.019.i = phi i64 [ %add.i.i, %for.body.i ], [ %add4.i, %for.body.i.preheader ]
  %conv.i.i = uitofp i64 %Gen.sroa.0.019.i to float
  %arrayidx.i.i = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %Gen.sroa.0.019.i
  %arrayidx.ascast.i.i = addrspacecast ptr addrspace(1) %arrayidx.i.i to ptr
  store float %conv.i.i, ptr %arrayidx.ascast.i.i, align 4, !tbaa !17
  %add.i.i = add i64 %Gen.sroa.0.019.i, %mul.i3
  %cmp6.i.not.i = icmp ult i64 %add.i.i, %0
  br i1 %cmp6.i.not.i, label %for.body.i, label %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit.loopexit, !llvm.loop !21

_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit.loopexit: ; preds = %for.body.i
  br label %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit

_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit: ; preds = %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit.loopexit, %entry
  ret void
}

; Function Attrs: convergent nounwind
declare dso_local noundef i64 @_Z22__spirv_GlobalOffset_xv() local_unnamed_addr #1

; Function Attrs: convergent norecurse nounwind
define weak_odr dso_local spir_kernel void @_ZTSZZ12foo_parallelRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlNS0_2idILi1EEEE_(ptr addrspace(1) noundef align 4 %_arg_acc, ptr noundef byval(%"class.sycl::_V1::range") align 8 %_arg_acc3) local_unnamed_addr #0 comdat !srcloc !23 !kernel_arg_buffer_location !24 !kernel_arg_runtime_aligned !25 !kernel_arg_exclusive_ptr !25 !sycl_fixed_targets !10 !sycl_kernel_omit_args !26 {
entry:
  %agg.tmp6.sroa.0.0.copyload = load i64, ptr %_arg_acc3, align 8
  %add.ptr.i = getelementptr inbounds float, ptr addrspace(1) %_arg_acc, i64 %agg.tmp6.sroa.0.0.copyload
  %call.i = tail call i64 @_Z21__spirv_WorkgroupId_xv() #5, !noalias !27
  %call1.i = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !27
  %mul.i = mul i64 %call1.i, %call.i
  %call2.i = tail call i64 @_Z27__spirv_LocalInvocationId_xv() #5, !noalias !27
  %add.i = add i64 %mul.i, %call2.i
  %call3.i = tail call i64 @_Z22__spirv_GlobalOffset_xv() #5, !noalias !27
  %add4.i = add i64 %add.i, %call3.i
  %call.i1 = tail call i64 @_Z23__spirv_NumWorkgroups_xv() #5, !noalias !27
  %call1.i2 = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !27
  %call.i.i.i9.i.i = tail call noundef i64 @_Z22__spirv_GlobalOffset_xv() #6, !noalias !27
  %cmp.i.i = icmp ult i64 %add4.i, 2147483648
  tail call void @llvm.assume(i1 %cmp.i.i)
  %conv.i = uitofp i64 %add4.i to float
  %arrayidx.i = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %add4.i
  %arrayidx.ascast.i = addrspacecast ptr addrspace(1) %arrayidx.i to ptr
  store float %conv.i, ptr %arrayidx.ascast.i, align 4, !tbaa !17
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #2

; Function Attrs: mustprogress norecurse nounwind
define weak_odr dso_local spir_kernel void @_ZTSZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlvE_(i64 noundef %_arg_n, ptr addrspace(1) noundef align 4 %_arg_acc, ptr noundef byval(%"class.sycl::_V1::range") align 8 %_arg_acc3) local_unnamed_addr #3 comdat !srcloc !32 !kernel_arg_buffer_location !8 !kernel_arg_runtime_aligned !9 !kernel_arg_exclusive_ptr !9 !sycl_fixed_targets !10 !sycl_kernel_omit_args !11 {
entry:
  %agg.tmp6.sroa.0.0.copyload = load i64, ptr %_arg_acc3, align 8
  %add.ptr.i = getelementptr inbounds float, ptr addrspace(1) %_arg_acc, i64 %agg.tmp6.sroa.0.0.copyload
  %cmp.i12.not = icmp eq i64 %_arg_n, 0
  br i1 %cmp.i12.not, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit, label %for.body.i.preheader

for.body.i.preheader:                             ; preds = %entry
  %xtraiter = and i64 %_arg_n, 7
  %0 = icmp ult i64 %_arg_n, 8
  br i1 %0, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, label %for.body.i.preheader.new

for.body.i.preheader.new:                         ; preds = %for.body.i.preheader
  %unroll_iter = and i64 %_arg_n, -8
  br label %for.body.i

for.body.i:                                       ; preds = %for.body.i, %for.body.i.preheader.new
  %i.0.i13 = phi i64 [ 0, %for.body.i.preheader.new ], [ %inc.i.7, %for.body.i ]
  %conv.i = uitofp i64 %i.0.i13 to float
  %arrayidx.i = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %i.0.i13
  %arrayidx.ascast.i = addrspacecast ptr addrspace(1) %arrayidx.i to ptr
  store float %conv.i, ptr %arrayidx.ascast.i, align 4, !tbaa !17
  %inc.i = or disjoint i64 %i.0.i13, 1
  %conv.i.1 = uitofp i64 %inc.i to float
  %arrayidx.i.1 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i
  %arrayidx.ascast.i.1 = addrspacecast ptr addrspace(1) %arrayidx.i.1 to ptr
  store float %conv.i.1, ptr %arrayidx.ascast.i.1, align 4, !tbaa !17
  %inc.i.1 = or disjoint i64 %i.0.i13, 2
  %conv.i.2 = uitofp i64 %inc.i.1 to float
  %arrayidx.i.2 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.1
  %arrayidx.ascast.i.2 = addrspacecast ptr addrspace(1) %arrayidx.i.2 to ptr
  store float %conv.i.2, ptr %arrayidx.ascast.i.2, align 4, !tbaa !17
  %inc.i.2 = or disjoint i64 %i.0.i13, 3
  %conv.i.3 = uitofp i64 %inc.i.2 to float
  %arrayidx.i.3 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.2
  %arrayidx.ascast.i.3 = addrspacecast ptr addrspace(1) %arrayidx.i.3 to ptr
  store float %conv.i.3, ptr %arrayidx.ascast.i.3, align 4, !tbaa !17
  %inc.i.3 = or disjoint i64 %i.0.i13, 4
  %conv.i.4 = uitofp i64 %inc.i.3 to float
  %arrayidx.i.4 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.3
  %arrayidx.ascast.i.4 = addrspacecast ptr addrspace(1) %arrayidx.i.4 to ptr
  store float %conv.i.4, ptr %arrayidx.ascast.i.4, align 4, !tbaa !17
  %inc.i.4 = or disjoint i64 %i.0.i13, 5
  %conv.i.5 = uitofp i64 %inc.i.4 to float
  %arrayidx.i.5 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.4
  %arrayidx.ascast.i.5 = addrspacecast ptr addrspace(1) %arrayidx.i.5 to ptr
  store float %conv.i.5, ptr %arrayidx.ascast.i.5, align 4, !tbaa !17
  %inc.i.5 = or disjoint i64 %i.0.i13, 6
  %conv.i.6 = uitofp i64 %inc.i.5 to float
  %arrayidx.i.6 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.5
  %arrayidx.ascast.i.6 = addrspacecast ptr addrspace(1) %arrayidx.i.6 to ptr
  store float %conv.i.6, ptr %arrayidx.ascast.i.6, align 4, !tbaa !17
  %inc.i.6 = or disjoint i64 %i.0.i13, 7
  %conv.i.7 = uitofp i64 %inc.i.6 to float
  %arrayidx.i.7 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.6
  %arrayidx.ascast.i.7 = addrspacecast ptr addrspace(1) %arrayidx.i.7 to ptr
  store float %conv.i.7, ptr %arrayidx.ascast.i.7, align 4, !tbaa !17
  %inc.i.7 = add nuw i64 %i.0.i13, 8
  %niter.ncmp.7 = icmp eq i64 %inc.i.7, %unroll_iter
  br i1 %niter.ncmp.7, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, label %for.body.i, !llvm.loop !33

_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa: ; preds = %for.body.i, %for.body.i.preheader
  %i.0.i13.unr = phi i64 [ 0, %for.body.i.preheader ], [ %unroll_iter, %for.body.i ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit, label %for.body.i.epil

for.body.i.epil:                                  ; preds = %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, %for.body.i.epil
  %i.0.i13.epil = phi i64 [ %inc.i.epil, %for.body.i.epil ], [ %i.0.i13.unr, %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %for.body.i.epil ], [ 0, %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa ]
  %conv.i.epil = uitofp i64 %i.0.i13.epil to float
  %arrayidx.i.epil = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %i.0.i13.epil
  %arrayidx.ascast.i.epil = addrspacecast ptr addrspace(1) %arrayidx.i.epil to ptr
  store float %conv.i.epil, ptr %arrayidx.ascast.i.epil, align 4, !tbaa !17
  %inc.i.epil = add nuw nsw i64 %i.0.i13.epil, 1
  %epil.iter.next = add nuw nsw i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit, label %for.body.i.epil, !llvm.loop !34

_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit: ; preds = %for.body.i.epil, %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, %entry
  ret void
}

; Function Attrs: convergent nounwind
declare dso_local i64 @_Z21__spirv_WorkgroupId_xv() local_unnamed_addr #4

; Function Attrs: convergent nounwind
declare dso_local i64 @_Z23__spirv_WorkgroupSize_xv() local_unnamed_addr #4

; Function Attrs: convergent nounwind
declare dso_local i64 @_Z27__spirv_LocalInvocationId_xv() local_unnamed_addr #4

; Function Attrs: convergent nounwind
declare dso_local i64 @_Z23__spirv_NumWorkgroups_xv() local_unnamed_addr #4

attributes #0 = { convergent norecurse nounwind "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="native_cpu.cpp" "sycl-optlevel"="2" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "uniform-work-group-size"="true" }
attributes #1 = { convergent nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #3 = { mustprogress norecurse nounwind "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="native_cpu.cpp" "sycl-optlevel"="2" "sycl-single-task" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "uniform-work-group-size"="true" }
attributes #4 = { convergent nounwind "frame-pointer"="all" "no-builtins" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+avx,+avx2,+avx512f,+cmov,+crc32,+cx8,+evex512,+f16c,+fma,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" "tune-cpu"="generic" }
attributes #5 = { convergent nobuiltin nounwind "no-builtins" }
attributes #6 = { convergent nounwind }

!opencl.spir.version = !{!0}
!spirv.Source = !{!1}
!llvm.ident = !{!2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2}
!llvm.module.flags = !{!3, !4, !5, !6}

!0 = !{i32 1, i32 2}
!1 = !{i32 4, i32 100000}
!2 = !{!"clang version 19.0.0git (https://github.com/intel/llvm.git f56d7d7ffd798e78146510bef7ba02575d53bbb2)"}
!3 = !{i32 1, !"wchar_size", i32 4}
!4 = !{i32 1, !"is-native-cpu", i32 1}
!5 = !{i32 7, !"uwtable", i32 2}
!6 = !{i32 7, !"frame-pointer", i32 2}
!7 = !{i32 8377463}
!8 = !{i32 -1, i32 -1, i32 -1}
!9 = !{i1 false, i1 true, i1 false}
!10 = !{}
!11 = !{i1 false, i1 false, i1 true, i1 true, i1 false}
!12 = !{!13, !15}
!13 = distinct !{!13, !14, !"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv: %agg.result"}
!14 = distinct !{!14, !"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv"}
!15 = distinct !{!15, !16, !"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE: %agg.result"}
!16 = distinct !{!16, !"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE"}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !19, i64 0}
!19 = !{!"omnipotent char", !20, i64 0}
!20 = !{!"Simple C++ TBAA"}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{i32 738}
!24 = !{i32 -1, i32 -1}
!25 = !{i1 true, i1 false}
!26 = !{i1 false, i1 true, i1 true, i1 false}
!27 = !{!28, !30}
!28 = distinct !{!28, !29, !"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv: %agg.result"}
!29 = distinct !{!29, !"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv"}
!30 = distinct !{!30, !31, !"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE: %agg.result"}
!31 = distinct !{!31, !"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE"}
!32 = !{i32 1035}
!33 = distinct !{!33, !22}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.unroll.disable"}

```

Comments: author: PietroGhg
body: Hi, this should be addressed by https://github.com/llvm/llvm-project/pull/92107

Fix patch:
commit 83d9aa27680b6a7f3556fcf13ada70b4be95bab2
Author: Pietro Ghiglio <pietro.ghiglio@codeplay.com>
Date:   Wed May 15 15:03:21 2024 +0200

    [VPlan] Add scalar inferencing support for addrspace cast (#92107)
    
    Fixes https://github.com/llvm/llvm-project/issues/91434
    
    PR: https://github.com/llvm/llvm-project/pull/92107

diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 5f93339083f0..efe8c21874a3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -171,6 +171,7 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) {
   case Instruction::ICmp:
   case Instruction::FCmp:
     return IntegerType::get(Ctx, 1);
+  case Instruction::AddrSpaceCast:
   case Instruction::Alloca:
   case Instruction::BitCast:
   case Instruction::Trunc:


Regression tests:
file: llvm/test/Transforms/LoopVectorize/as_cast.ll
commands: opt -passes=loop-vectorize %s -force-vector-width=1 -force-vector-interleave=2 -S -o -
tests: test_name: <module>
test_body: 
define void @foo(ptr addrspace(1) %in) {
entry:
  br label %loop

loop:
  %iter = phi i64 [ %next, %loop ], [ 0, %entry ]
  %ascast = addrspacecast ptr addrspace(1) %in to ptr
  %next = add i64 %iter, 1
  %arrayidx = getelementptr inbounds i64, ptr %ascast, i64 %next
  store i64 %next, ptr %arrayidx, align 4

; check that we find the two interleaved blocks with ascast, gep and store:


  %cmp = icmp eq i64 %next, 7
  br i1 %cmp, label %exit, label %loop

; check that we branch to the exit block

exit:
  ret void
}