[all-commits] [llvm/llvm-project] e8744b: [InstCombine] Add tests for (A > 0) | (A < 0) -> z...
XChy via All-commits
all-commits at lists.llvm.org
Thu Jul 6 00:03:14 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: e8744ba32d56cd098aaf40d3845a43fc31e42291
https://github.com/llvm/llvm-project/commit/e8744ba32d56cd098aaf40d3845a43fc31e42291
Author: XChy <xxs_chy at outlook.com>
Date: 2023-07-06 (Thu, 06 Jul 2023)
Changed paths:
M llvm/test/Transforms/InstCombine/and-or-icmps.ll
Log Message:
-----------
[InstCombine] Add tests for (A > 0) | (A < 0) -> zext (A != 0) fold (NFC)
Tests for an upcoming (A > 0) | (A < 0) -> zext (A != 0) fold.
Related issue:
[[ https://github.com/llvm/llvm-project/issues/62586 | (a > b) | (a < b) is not simplified only for the case b=0 ]]
Differential Revision: https://reviews.llvm.org/D154089
Commit: bfb5d2e6f854f16eb4f4d49ce8c0160f89584a00
https://github.com/llvm/llvm-project/commit/bfb5d2e6f854f16eb4f4d49ce8c0160f89584a00
Author: XChy <xxs_chy at outlook.com>
Date: 2023-07-06 (Thu, 06 Jul 2023)
Changed paths:
M llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
M llvm/test/Transforms/InstCombine/and-or-icmps.ll
Log Message:
-----------
[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
Compare: https://github.com/llvm/llvm-project/compare/ca01be54c1e9...bfb5d2e6f854
More information about the All-commits
mailing list