[InstCombine] Fix assertion failure in issue80597 (#80614)
authorYingwei Zheng <dtcxzyw2333@gmail.com>
Mon, 5 Feb 2024 17:29:38 +0000 (01:29 +0800)
committerTom Stellard <tstellar@redhat.com>
Tue, 6 Feb 2024 23:40:40 +0000 (15:40 -0800)
commit7a9e4184fbb17d31265253f69b3bf5217c0d967c
tree22e93ad8ce1256d8cb4fb782a809f4cd8e26cbac
parent8835ba873031a412595de2ce90e46fb65e93d214
[InstCombine] Fix assertion failure in issue80597 (#80614)

The assertion in #80597 failed when we were trying to compute known bits
of a value in an unreachable BB.

https://github.com/llvm/llvm-project/blob/859b09da08c2a47026ba0a7d2f21b7dca705864d/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L749-L810

In this case, `SignBits` is 30 (deduced from instr info), but `Known` is
`10000101010111010011110101000?0?00000000000000000000000000000000`
(deduced from dom cond). Setting high bits of `lshr Known, 1` will lead
to conflict.

This patch masks out high bits of `Known.Zero` to address this problem.

Fixes #80597.

(cherry picked from commit cb8d83a77c25e529f58eba17bb1ec76069a04e90)
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/test/Transforms/InstCombine/pr80597.ll [new file with mode: 0644]