[InstCombine] Combine binary operator of two phi node
authorluxufan <luxufan@iscas.ac.cn>
Fri, 3 Mar 2023 08:34:17 +0000 (16:34 +0800)
committerluxufan <luxufan@iscas.ac.cn>
Tue, 21 Mar 2023 07:24:17 +0000 (15:24 +0800)
commit6beb371e4c469801e04711b81d27cde6da11b032
tree6f5236f983c5602d9196ef7aa37cb10f94c91532
parent9c93e728bfb8079c1de51e5481168c4083038c2a
[InstCombine] Combine binary operator of two phi node

Combine binary operator of two phi node if there is at least one
specific constant value in phi0 and phi1's incoming values for each
same incoming block and this specific constant value can be used
to do optimization for specific binary operator.
For example:
```
%phi0 = phi i32 [0, %bb0], [%i, %bb1]
%phi1 = phi i32 [%j, %bb0], [0, %bb1]
%add = add i32 %phi0, %phi1
==>
%add = phi i32 [%j, %bb0], [%i, %bb1]
```

Fixes: https://github.com/llvm/llvm-project/issues/61137

Differential Revision: https://reviews.llvm.org/D145223
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/phi.ll