[CVP] Use simpler urem expansion when LHS >= RHS (PR63330)
authorNikita Popov <npopov@redhat.com>
Mon, 19 Jun 2023 15:14:37 +0000 (17:14 +0200)
committerNikita Popov <npopov@redhat.com>
Mon, 19 Jun 2023 15:16:49 +0000 (17:16 +0200)
commit7cfc82f331182855e2634c21d242c3b418f84bd1
treef23909fb68e7223341344405d582636af9401bb4
parentbb4f4a3efeae2bc0785edc19d2347f21729c816c
[CVP] Use simpler urem expansion when LHS >= RHS (PR63330)

In this case we don't need to emit the comparison and select.

This is papering over a weakness in CVP in that newly added
instructions don't get revisited. If they were revisited, the
icmp would be folded at that point.

However, even without that it makes sense to handle this explicitly,
because it avoids the need to insert freeze, which may prevent
further analysis of the operation by LVI.

Proofs: https://alive2.llvm.org/ce/z/quyBxp

Fixes https://github.com/llvm/llvm-project/issues/63330.
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/CorrelatedValuePropagation/udiv-expansion.ll
llvm/test/Transforms/CorrelatedValuePropagation/urem-expansion.ll