[InstCombine] Fix bug in `FoldOpIntoSelect` where we would incorrectly fold `undef...
authorNoah Goldstein <goldstein.w.n@gmail.com>
Mon, 1 May 2023 20:37:11 +0000 (15:37 -0500)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Mon, 1 May 2023 22:23:54 +0000 (17:23 -0500)
commit6cdc229a64be8dacba40d30a9032c14f51ee30c0
tree63064f65d04f5d90cd84af7730daf774b00fd743
parent819d1e860ea7b10f609ca78099878e6e2dcdeeb1
[InstCombine] Fix bug in `FoldOpIntoSelect` where we would incorrectly fold `undef` as constant

D146349 Introduced the ability to use the information from the
`select` condition to deduce constants as we folded a binop into
select. I.e if the `select` cond was `icmp eq %A, 10`, then in the
true-arm of `select`, we would be able to replace usage of `A` with
`10`.

This is broken for vectors that contain `undef` elements. I.e with
`icmp eq %A, <10, undef>`, subsituting `<10, undef>` for `A` can
result in creating a more undefined result than we otherwise would
have.

We fix the issue with simply checking if the candidate constant for
substituting may contain `undef` elements and don't do it in that
case.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D149592
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/binop-select.ll