Given this function:
define i64 @incorrect_safe_div(i64 %n, i64 %d) {
%1 = icmp eq i64 %d, 0
%2 = udiv i64 %n, %d
%3 = select i1 %1, i64 -1, i64 %2
ret i64 %3
}
LLVM does not seem to notice that this select is unconditional, because %2 should imply that %d != 0 in the entire block, and therefore %1 can be replaced with false. Alive2 confirms this optimization is valid: https://alive2.llvm.org/ce/z/7nLDRe.