[llvm] [InstSimplify] Simplify select if it combinated `and/or/xor` (PR #73362)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 08:29:16 PST 2023
================
@@ -4425,6 +4425,61 @@ 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;
+ }
----------------
goldsteinn wrote:
Think you still need the boolean for if the predicate is eq or ne. Otherwise in the `(X & Y) != 0 ? X | Y : X ^ Y` you will be returning `X ^ Y` instead of `X | Y`.
https://github.com/llvm/llvm-project/pull/73362
More information about the llvm-commits
mailing list