[SCCP] convert signed div/rem to unsigned for non-negative operands, 2nd try
authorSanjay Patel <spatel@rotateright.com>
Wed, 7 Sep 2022 15:44:27 +0000 (11:44 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 7 Sep 2022 15:56:29 +0000 (11:56 -0400)
commit85b289377bff14790f402e5ea84bb24168a68fc6
tree6ddd825c19d2480d3641d1d4b22c385af06d14f4
parente5a8f50ab160c56a316e79f46e787afa15c1cbcc
[SCCP] convert signed div/rem to unsigned for non-negative operands, 2nd try

The original commit ( fe1f3cfc2669 ) was reverted because it could
crash / assert when trying to fold a value that was replaced
by a constant. In that case, there might not be an entry for the
constant in the solver yet.

This version adds a check for that possibility along with tests to
exercise that pattern (they used to crash).

Original commit message:
This extends the transform added with D81756 to handle div/rem opcodes.
For example:
https://alive2.llvm.org/ce/z/cX6za6

This replicates part of what CVP already does, but the motivating example
from issue #57472 demonstrates a phase ordering problem - we convert
branches to select before CVP runs and miss the transform.

Differential Revision: https://reviews.llvm.org/D133198
llvm/lib/Transforms/Scalar/SCCP.cpp
llvm/test/Transforms/PhaseOrdering/srem.ll
llvm/test/Transforms/SCCP/binaryops-range-special-cases.ll
llvm/test/Transforms/SCCP/divrem-crash.ll [new file with mode: 0644]
llvm/test/Transforms/SCCP/divrem.ll