[llvm] [InstSimplify] Simplify select if it combinated `and/or/xor` (PR #73362)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 09:48:46 PST 2023
================
@@ -4425,6 +4425,60 @@ Value *llvm::simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
RecursionLimit);
}
+/// Try simplifying the selection command when condition, trueValue, and
+/// falseValue are combinations of special bitwise operators.
+static Value *simplifySelectBitTestSpec(Value *CmpLHS, Value *CmpRHS,
+ Value *TrueVal, Value *FalseVal) {
+ Value *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
+ if (match(CmpLHS, m_c_And(m_Value(X), m_Value(Y))) &&
+ match(CmpRHS, m_Zero())) {
+ if (match(TrueVal, m_c_Or(m_Specific(X), m_Specific(Y))) &&
+ match(FalseVal, m_c_Xor(m_Specific(X), m_Specific(Y)))) {
+ return FalseVal;
+ } else if (match(FalseVal, m_c_Or(m_Specific(X), m_Specific(Y))) &&
+ match(TrueVal, m_c_Xor(m_Specific(X), m_Specific(Y)))) {
+ return FalseVal;
+ }
+ }
+ // (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
+ if (match(CmpLHS, m_c_Or(m_Value(X), m_Value(Y))) &&
+ match(CmpRHS, m_Zero())) {
+ if (match(TrueVal, m_c_And(m_Specific(X), m_Specific(Y))) &&
+ match(FalseVal, m_c_Xor(m_Specific(X), m_Specific(Y)))) {
+ return FalseVal;
+ } else if (match(FalseVal, m_c_And(m_Specific(X), m_Specific(Y))) &&
+ match(TrueVal, m_c_Xor(m_Specific(X), m_Specific(Y)))) {
+ return FalseVal;
+ }
+ }
+ // (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 could be transformed to X == Y
+ // (X ^ Y) != 0 could be transformed to X != Y
+ if (match(CmpLHS, m_CombineOr(m_c_Xor(m_Value(X), m_Value(Y)), m_Value(X)))) {
----------------
ParkHanbum wrote:
I got it. thanks to know
https://github.com/llvm/llvm-project/pull/73362
More information about the llvm-commits
mailing list