[llvm] [llvm][instcombine] Add Missed Optimization for Folding Min Max intrinsic into PHI instruction (PR #84619)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 07:48:59 PDT 2024


PeterChou1 wrote:

> Could you please provide the alive2 proof for general cases?

Sure, I've construct alive2 proofs for every case in the optimization below

min intrinsic optimization only works if x >= z
```
%min = llvm.umin ( X, Y )
%phi = phi %min ...         =>  %phi = phi Y ..
%cmp = icmp ult %phi, Z          %cmp = icmp ult %phi, Z
```
case 1. x = z should optimize: https://alive2.llvm.org/ce/z/IAXE_-
case 2. x > z should optimize: https://alive2.llvm.org/ce/z/cSqDmr
case 3. x < z should NOT optimize: https://alive2.llvm.org/ce/z/7r0b4A

swapped min intrinsic optimization only works if x >= z
```
%min = llvm.umin ( X, Y )
%phi = phi %min ...             =>  %phi = phi Y ..
%cmp = icmp ugt Z, %phi          %cmp = icmp ugt %phi, Z
```
case 5. x = z should optimize: https://alive2.llvm.org/ce/z/8RZEVx
case 6. x > z should optimize: https://alive2.llvm.org/ce/z/8cgUAV
case 7. x < z should NOT optimize: https://alive2.llvm.org/ce/z/S_f5bU

max intrinsic optimization only works if x <= z
```
%max = llvm.umax ( X, Y )
%phi = phi %max ...         =>  %phi = phi Y ..
%cmp = icmp ugt %phi, Z          %cmp = icmp ugt %phi, Z
```
case 8. x = z should optimize: https://alive2.llvm.org/ce/z/QYFiRR
case 9. x < z should optimize: https://alive2.llvm.org/ce/z/djpU8u
case 10. x > z should NOT optimize: https://alive2.llvm.org/ce/z/2S3seD

swapped max intrinsic optimization only works if x <= z
```
%max = llvm.umax ( X, Y )
%phi  = phi %max ...         =>   %phi = phi Y ..
%cmp = icmp ult Z, %phi          %cmp = icmp ult Z, %phi  
```
case 11. x = z should optimize: https://alive2.llvm.org/ce/z/B7VRzx
case 12. x < z should optimize: https://alive2.llvm.org/ce/z/5UuFHF
case 13. x > z should NOT optimize: https://alive2.llvm.org/ce/z/wAwfex

These proofs generalize over smin, and smax intrinsics as well, but I will omit them for brevity

https://github.com/llvm/llvm-project/pull/84619


More information about the llvm-commits mailing list