Reapply [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>
Fri, 7 Oct 2022 09:04:19 +0000 (11:04 +0200)
commit333246b48ea4a70842e78c977cc92d365720465f
treeead6f35c68004799a7c8574464bf7f3aef2e7650
parent02c1c939486f247dc80866477eaab193c634d1e2
Reapply [InstCombine] Switch foldOpIntoPhi() to use InstSimplify

Relative to the previous attempt, this adjusts simplification to
use the correct context instruction: We need to use the terminator
of the incoming block, not the original instruction.

-----

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.

Differential Revision: https://reviews.llvm.org/D134954
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