Index: llvm/lib/Analysis/InstructionSimplify.cpp =================================================================== --- llvm/lib/Analysis/InstructionSimplify.cpp +++ llvm/lib/Analysis/InstructionSimplify.cpp @@ -499,6 +499,11 @@ if (TCmp == FCmp) return TCmp; + // It is not safe to propagate poison to the compare unless both arms of the + // select were poison. + if (isa(TCmp) || isa(FCmp)) + return nullptr; + // The remaining cases only make sense if the select condition has the same // type as the result of the comparison, so bail out if this is not so. if (Cond->getType()->isVectorTy() == RHS->getType()->isVectorTy()) Index: llvm/test/Transforms/InstCombine/icmp.ll =================================================================== --- llvm/test/Transforms/InstCombine/icmp.ll +++ llvm/test/Transforms/InstCombine/icmp.ll @@ -3935,7 +3935,7 @@ define i1 @thread_cmp_over_select_with_poison_trueval(i1 %b) { ; CHECK-LABEL: @thread_cmp_over_select_with_poison_trueval( -; CHECK-NEXT: ret i1 poison +; CHECK-NEXT: ret i1 false ; %s = select i1 %b, i32 poison, i32 0 %tobool = icmp ne i32 %s, 0 @@ -3944,7 +3944,7 @@ define i1 @thread_cmp_over_select_with_poison_falseval(i1 %b) { ; CHECK-LABEL: @thread_cmp_over_select_with_poison_falseval( -; CHECK-NEXT: ret i1 poison +; CHECK-NEXT: ret i1 true ; %s = select i1 %b, i32 1, i32 poison %tobool = icmp ne i32 %s, 0