[InstCombine] Transform (A > 0) | (A < 0) -> zext (A != 0) fold
[InstCombine] Transform (A > 0) | (A < 0) -> zext (A != 0) fold This extends **foldCastedBitwiseLogic** to handle the similar cases. Actually, for `(A > B) | (A < B)`, when B != 0, it can be optimized to `zext( A != B )` by **foldAndOrOfICmpsUsingRanges**. However, when B = 0, **transformZExtICmp** will transform `zext(A < 0) to i32` into `A << 31`, which cannot be optimized by **foldAndOrOfICmpsUsingRanges**. Because I'm new to LLVM and has no concise knowledge about how LLVM decides the order of optimization, I choose to extend **foldCastedBitwiseLogic** to fold `( A << (X - 1) ) | ((A > 0) zext to iX) -> (A != 0) zext to iX`. And the equivalent fold follows: ``` A << (X - 1) ) | ((A > 0) zext to iX -> A < 0 | A > 0 -> (A != 0) zext to iX ``` It's proved by [[https://alive2.llvm.org/ce/z/33HzjE|alive-tv]] Related issue: [[https://github.com/llvm/llvm-project/issues/62586 | (a > b) | (a < b) is not simplified only for the case b=0 ]] Reviewed By: goldstein.w.n Differential Revision: https://reviews.llvm.org/D154126
Loading
Please sign in to comment