[InstCombine] Switch foldOpIntoPhi() to use InstSimplify
authorNikita Popov <npopov@redhat.com>
Fri, 30 Sep 2022 10:13:40 +0000 (12:13 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 4 Oct 2022 08:12:14 +0000 (10:12 +0200)
commitb20e34b39f72f2be035dfb7367b6880fd2cf213a
tree9da98bde5f1c22bb998d08a725d019b872e3c257
parent9d99b482cdc288dabe5ec1924177238d438ef093
[InstCombine] Switch foldOpIntoPhi() to use InstSimplify

foldOpIntoPhi() currently only folds operations into the phi if all
but one operands constant-fold. The two exceptions to this are freeze
and select, where we allow more general simplification.

This patch makes foldOpIntoPhi() generally simplification based and
removes all the instruction-specific logic. We just try to simplify
the instruction for each operand, and for the (potentially) one
non-simplified operand, we move it into the new block with adjusted
operands.

This fixes https://github.com/llvm/llvm-project/issues/57448, which
was my original motivation for the change.
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/intptr1.ll
llvm/test/Transforms/InstCombine/intptr4.ll
llvm/test/Transforms/InstCombine/intptr5.ll
llvm/test/Transforms/InstCombine/intptr7.ll
llvm/test/Transforms/InstCombine/phi-select-constant.ll
llvm/test/Transforms/InstCombine/phi.ll
llvm/test/Transforms/InstCombine/recurrence.ll