New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplification Comparison for (a | b) ? (a ^ b) : (a & b)
etc. (Clang13 vs Clang trunk)
#71792
Comments
Sorry, maybe I should have made a comparison with Clang14. |
maybe this patch causes this. But to me, the patch seems to have a clear purpose. There is a possibility that it can be solved by removing it, but it is questionable whether this is a desirable direction. if this issue not need to fix fast then I want to try. |
- `(icmp eq (and/or (ext (A)), (ext (B)), 1)` - `(icmp ne (and/or (ext (A)), (ext (B)), 0)` -> `(and/or A, B)` - `(icmp eq (and/or (ext (A)), (ext (B)), 0) - `(icmp ne (and/or (ext (A)), (ext (B)), 1) -> `!(and/or A, B)` If A and B are of type i1, perform the above conversion. Proofs: https://alive2.llvm.org/ce/z/c-nrLX Fixes llvm#71792.
Unlike the cause of the issue, the way to solve it has become more complicated. reason is that LLVM has decided to no longer allow casting after operation if operator has two casted operand. maybe this can solved one of followed way.
first, assume that we got the ir like below
It will change as follows
we already know (X|B=0) when (X^Y)=0
even if you change just this, the results will change.
and apply same logic to
as this way. this issue could be solved. IMO |
- (X & Y) == 0 ? X | Y : X ^ Y --> X ^ Y - (X & Y) != 0 ? X | Y : X ^ Y --> X | Y - (X | Y) == 0 ? X & Y : X ^ Y --> X ^ Y - (X | Y) != 0 ? X & Y : X ^ Y --> X & Y - (X ^ Y) == 0 ? X | Y : X & Y --> X & Y - (X ^ Y) != 0 ? X | Y : X & Y --> X | Y certain combinations of bitwise operators can be simplified to returning the value of the True or False clause. Proofs : https://alive2.llvm.org/ce/z/HDSzm4 Fixed llvm#71792.
- (X & Y) == 0 ? X | Y : X ^ Y --> X ^ Y - (X & Y) != 0 ? X | Y : X ^ Y --> X | Y - (X | Y) == 0 ? X & Y : X ^ Y --> X ^ Y - (X | Y) != 0 ? X & Y : X ^ Y --> X & Y - (X ^ Y) == 0 ? X | Y : X & Y --> X & Y - (X ^ Y) != 0 ? X | Y : X & Y --> X | Y certain combinations of bitwise operators can be simplified to returning the value of the True or False clause. Proofs : https://alive2.llvm.org/ce/z/HDSzm4 Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixed llvm#71792.
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR
`and/or/xor` operations can each be changed to sum of logical operations including operators other than themselves. `x&y -> (x|y) ^ (x^y)` `x|y -> (x&y) | (x^y)` `x^y -> (x|y) ^ (x&y)` if left of condition of `SelectInst` is `and/or/xor` logical operation and right is equal to `0, -1`, or a `constant`, and if `TrueVal` consist of `and/or/xor` logical operation then we can optimize this case. This patch implements this combination. Proof: https://alive2.llvm.org/ce/z/WW8iRR Fixes #71792.
Consider the following six functions.
https://godbolt.org/z/cTsd43jhh
Clang13 can simplify four of these,
test1
,test2
,test3
andtest4
, while Clang trunk cannot. Neither Clang13 nor Clang trunk can simplifytest5
andtest6
.The text was updated successfully, but these errors were encountered: