[InstCombine] Transform X == 0 ? 0 : X * Y --> X * freeze(Y)
authorFilipp Zhinkin <filipp.zhinkin@gmail.com>
Wed, 15 Sep 2021 13:04:06 +0000 (09:04 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 15 Sep 2021 13:04:06 +0000 (09:04 -0400)
commitf5d89523567b08420ff3fa48a6fc50dbf530afa8
tree559166fe8d8cad6becbc0a92bd90ed94ae97ebea
parentbe1028053e935524620de91a30035f1ff0a7f9aa
[InstCombine] Transform X == 0 ? 0 : X * Y --> X * freeze(Y)

Enabled mul folding optimization that was previously disabled
by being incorrect.
To preserve correctness, mul's operand that is not compared
with zero in select's condition is now frozen.

Related bug: https://bugs.llvm.org/show_bug.cgi?id=51286

Correctness:
https://alive2.llvm.org/ce/z/bHef7J
https://alive2.llvm.org/ce/z/QcR7sf
https://alive2.llvm.org/ce/z/vvBLzt
https://alive2.llvm.org/ce/z/jGDXgq
https://alive2.llvm.org/ce/z/3Pe8Z4
https://alive2.llvm.org/ce/z/LGga8M
https://alive2.llvm.org/ce/z/CTG5fs

Differential Revision: https://reviews.llvm.org/D108408
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select.ll