[llvm] [InstSimplify] Simplify select if it combinated `and/or/xor` (PR #73362)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 26 16:23:44 PST 2023
================
@@ -4425,6 +4425,48 @@ 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 *TrueVal, Value *FalseVal,
+ Value *X, Value *Y,
+ bool TrueWhenUnset) {
+ // (X & Y) == 0 ? X | Y : X ^ Y --> X ^ Y
+ // (X & Y) == 0 ? X ^ Y : X | Y --> X | Y
+ // (X & Y) == 1 ? X | Y : X ^ Y --> X | Y
+ // (X & Y) == 1 ? X ^ Y : X | Y --> X ^ Y
+ if (match(TrueVal, m_Or(m_Specific(X), m_Specific(Y))) &&
+ match(FalseVal, m_Xor(m_Specific(X), m_Specific(Y)))) {
+ return TrueWhenUnset ? TrueVal : FalseVal;
+ } else if (match(FalseVal, m_Or(m_Specific(X), m_Specific(Y))) &&
+ match(TrueVal, m_Xor(m_Specific(X), m_Specific(Y)))) {
+ return TrueWhenUnset ? TrueVal : FalseVal;
+ }
+ // (X | Y) == 0 ? X & Y : X ^ Y --> X ^ Y
+ // (X | Y) == 0 ? X ^ Y : X & Y --> X & Y
+ // (X | Y) == 1 ? X & Y : X ^ Y --> X & Y
+ // (X | Y) == 1 ? X ^ Y : X & Y --> X ^ Y
+ if (match(TrueVal, m_And(m_Specific(X), m_Specific(Y))) &&
+ match(FalseVal, m_Xor(m_Specific(X), m_Specific(Y)))) {
+ return TrueWhenUnset ? TrueVal : FalseVal;
+ } else if (match(FalseVal, m_And(m_Specific(X), m_Specific(Y))) &&
+ match(TrueVal, m_Xor(m_Specific(X), m_Specific(Y)))) {
+ return TrueWhenUnset ? TrueVal : FalseVal;
+ }
+ // (X ^ Y) == 0 ? X | Y : X & Y --> X & Y
+ // (X ^ Y) == 0 ? X & Y : X | Y --> X | Y
+ // (X ^ Y) == 1 ? X | Y : X & Y --> X | Y
+ // (X ^ Y) == 1 ? X & Y : X | Y --> X & Y
+ if (match(TrueVal, m_Or(m_Specific(X), m_Specific(Y))) &&
+ match(FalseVal, m_Xor(m_Specific(X), m_Specific(Y)))) {
+ return TrueWhenUnset ? TrueVal : FalseVal;
+ } else if (match(FalseVal, m_Or(m_Specific(X), m_Specific(Y))) &&
+ match(TrueVal, m_Xor(m_Specific(X), m_Specific(Y)))) {
+ return TrueWhenUnset ? TrueVal : FalseVal;
----------------
ParkHanbum wrote:
did it! thanks!
https://github.com/llvm/llvm-project/pull/73362
More information about the llvm-commits
mailing list