Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5274,12 +5274,16 @@ return llvm::None; } + // may be all elements are under value + if (C->containsUndefOrPoisonElement() && + SafeReplacementConstant == nullptr) + return llvm::None; + // It may not be safe to change a compare predicate in the presence of // undefined elements, so replace those elements with the first safe constant // that we found. // TODO: in case of poison, it is safe; let's replace undefs only. if (C->containsUndefOrPoisonElement()) { - assert(SafeReplacementConstant && "Replacement constant not set"); C = Constant::replaceUndefsWith(C, SafeReplacementConstant); } Index: llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll =================================================================== --- llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll +++ llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll @@ -125,3 +125,14 @@ %cmp = icmp slt i27 %cast, 262657 ; 0x040201 ret i1 %cmp } + +; Verify the case that all elements are under define +define <4 x i1> @test_i32_ule_pattern(i32 %val) { +; CHECK-LABEL: @test_i32_ule_pattern( +; CHECK-NEXT: ret <4 x i1> +; + %insvec = insertelement <4 x i32> poison, i32 %val, i32 0 + %vec = shufflevector <4 x i32> %insvec, <4 x i32> poison, <4 x i32> zeroinitializer + %cond = icmp ule <4 x i32> %vec, + ret <4 x i1> %cond +}