[InstCombine] Add check for flag propagation in `foldSelectIntoOp` (#173735)

Fixes
https://github.com/llvm/llvm-project/pull/162003#issuecomment-3693943568.

The current flag propagation assumes that if a select has both `ninf`
and `nnan`, then the operands of the folded operation must be finite.
While this assumption holds for `fadd`, `fsub`, and `fmul`, it does not
hold for `fdiv`.

For example, assume we have:

```
A = 1.0, B = +Inf
A / B = 0.0  (finite, non-NaN)
```

The current transform would turn `fdiv A, B; select ninf nnan cond, A/B,
A;` into `A / (select ninf nnan cond, B, 1.0)`. If `cond` is true, the
inner select returns `B = +Inf`, and due to the propagated `ninf`, this
becomes poison.

This patch add check for operators before flag propagation to avoid
`fdiv` cases.

Alive2: https://alive2.llvm.org/ce/z/o0MJmS
GitOrigin-RevId: a7d8b88d1818d9eeb4e21de80f09719ca7ecb51a
2 files changed