[InstCombine] try to fold binop with phi operands
authorSanjay Patel <spatel@rotateright.com>
Sat, 22 Jan 2022 17:36:12 +0000 (12:36 -0500)
committerSanjay Patel <spatel@rotateright.com>
Sat, 22 Jan 2022 20:00:06 +0000 (15:00 -0500)
commit39e602b6c4335b2572c74eaf9a666bebde7fd8b5
treeb81566a49e528f30d7a9df850abd6ebcedede079
parentd44b6be6eaa8c165d3526d61dcc0f1c459e5722f
[InstCombine] try to fold binop with phi operands

This is an alternate version of D115914 that handles/tests all binary opcodes.

I suspect that we don't see these patterns too often because -simplifycfg
would convert the minimal cases into selects rather than leave them in phi form
(note: instcombine has logic holes for combining the select patterns too though,
so that's another potential patch).

We only create a new binop in a predecessor that unconditionally branches to
the final block.
https://alive2.llvm.org/ce/z/C57M2F
https://alive2.llvm.org/ce/z/WHwAoU (not safe to speculate an sdiv for example)
https://alive2.llvm.org/ce/z/rdVUvW (but it is ok on this path)

Differential Revision: https://reviews.llvm.org/D117110
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/binop-phi-operands.ll
llvm/test/Transforms/InstCombine/zext-or-icmp.ll