[InstCombine] prevent miscompiles from select-of-div/rem transform
authorSanjay Patel <spatel@rotateright.com>
Wed, 1 Mar 2023 13:32:27 +0000 (08:32 -0500)
committerSanjay Patel <spatel@rotateright.com>
Wed, 1 Mar 2023 13:54:23 +0000 (08:54 -0500)
commit452279efe21a61c7e17189da99347f7755f27cb0
treeb2c178369b8e40fa7a0264b4bf2516909a5056ab
parent83bbd3fdbd75295669cf97967c38810d427c5c25
[InstCombine] prevent miscompiles from select-of-div/rem transform

This avoids the danger shown in issue #60906.
There were no regression tests for these patterns, so these potential
failures have been around for a long time.

We freeze the condition and preserve the optimization because
getting rid of a div/rem is always a win.

Here are a couple of examples that can be corrected by freezing the
condition:
https://alive2.llvm.org/ce/z/sXHTTC

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