mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
Third time's a charm.
The previous patches didn't match correctly. Also, we need to make sure that the conditional is the same before doing the transformation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58978 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -4354,70 +4354,68 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_SELECT_COND(Val) \
|
#define SELECT_MATCH(Val, I1, I2) \
|
||||||
cast<User>(Val)->getOperand(0)
|
m_Select(m_Value(Val), m_ConstantInt(I1), m_ConstantInt(I2))
|
||||||
#define SELECT_MATCH(Val) \
|
|
||||||
m_Select(m_Value(Val), m_ConstantInt(0), m_ConstantInt(-1))
|
|
||||||
|
|
||||||
// (A & (C0?-1:0)) | (B & ~(C0?-1:0)) -> C0 ? A : B, and commuted variants
|
// (A & (C0?-1:0)) | (B & ~(C0?-1:0)) -> C0 ? A : B, and commuted variants
|
||||||
if (match(A, m_Select(m_Value(), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
Value *C0 = 0;
|
||||||
Value *Cond = GET_SELECT_COND(A);
|
if (match(A, m_Select(m_Value(C0), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
||||||
if (match(D, m_Not(SELECT_MATCH(Cond))))
|
Value *C1 = 0;
|
||||||
return SelectInst::Create(Cond, C, B);
|
if (match(D, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
if (match(B, m_Not(SELECT_MATCH(Cond))))
|
return SelectInst::Create(C1, C, B);
|
||||||
return SelectInst::Create(Cond, C, D);
|
if (match(B, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
|
return SelectInst::Create(C1, C, D);
|
||||||
}
|
}
|
||||||
if (match(B, m_Select(m_Value(), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
if (match(B, m_Select(m_Value(C0), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
||||||
Value *Cond = GET_SELECT_COND(B);
|
Value *C1 = 0;
|
||||||
if (match(C, m_Not(SELECT_MATCH(Cond))))
|
if (match(C, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, A, D);
|
return SelectInst::Create(C1, A, D);
|
||||||
if (match(A, m_Not(SELECT_MATCH(Cond))))
|
if (match(A, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, C, D);
|
return SelectInst::Create(C1, C, D);
|
||||||
}
|
}
|
||||||
if (match(C, m_Select(m_Value(), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
if (match(C, m_Select(m_Value(C0), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
||||||
Value *Cond = GET_SELECT_COND(C);
|
Value *C1 = 0;
|
||||||
if (match(D, m_Not(SELECT_MATCH(Cond))))
|
if (match(D, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, A, B);
|
return SelectInst::Create(C1, A, B);
|
||||||
if (match(B, m_Not(SELECT_MATCH(Cond))))
|
if (match(B, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, A, D);
|
return SelectInst::Create(C1, A, D);
|
||||||
}
|
}
|
||||||
if (match(D, m_Select(m_Value(), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
if (match(D, m_Select(m_Value(C0), m_ConstantInt(-1), m_ConstantInt(0)))) {
|
||||||
Value *Cond = GET_SELECT_COND(D);
|
Value *C1 = 0;
|
||||||
if (match(C, m_Not(SELECT_MATCH(Cond))))
|
if (match(C, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, A, B);
|
return SelectInst::Create(C1, A, B);
|
||||||
if (match(A, m_Not(SELECT_MATCH(Cond))))
|
if (match(A, m_Not(SELECT_MATCH(C1, -1, 0))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, C, B);
|
return SelectInst::Create(C1, C, B);
|
||||||
}
|
}
|
||||||
if (match(A, m_Select(m_Value(), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
if (match(A, m_Select(m_Value(C0), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
||||||
Value *Cond = GET_SELECT_COND(A);
|
Value *C1 = 0;
|
||||||
if (match(D, m_Not(SELECT_MATCH(Cond))))
|
if (match(D, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, B, C);
|
return SelectInst::Create(C1, B, C);
|
||||||
if (match(B, m_Not(SELECT_MATCH(Cond))))
|
if (match(B, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, D, C);
|
return SelectInst::Create(C1, D, C);
|
||||||
}
|
}
|
||||||
if (match(B, m_Select(m_Value(), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
if (match(B, m_Select(m_Value(C0), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
||||||
Value *Cond = GET_SELECT_COND(B);
|
Value *C1 = 0;
|
||||||
if (match(C, m_Not(SELECT_MATCH(Cond))))
|
if (match(C, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, D, A);
|
return SelectInst::Create(C1, D, A);
|
||||||
if (match(A, m_Not(SELECT_MATCH(Cond))))
|
if (match(A, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, D, C);
|
return SelectInst::Create(C1, D, C);
|
||||||
}
|
}
|
||||||
if (match(C, m_Select(m_Value(), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
if (match(C, m_Select(m_Value(C0), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
||||||
Value *Cond = GET_SELECT_COND(C);
|
Value *C1 = 0;
|
||||||
if (match(D, m_Not(SELECT_MATCH(Cond))))
|
if (match(D, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, B, A);
|
return SelectInst::Create(C1, B, A);
|
||||||
if (match(B, m_Not(SELECT_MATCH(Cond))))
|
if (match(B, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, D, A);
|
return SelectInst::Create(C1, D, A);
|
||||||
}
|
}
|
||||||
if (match(D, m_Select(m_Value(), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
if (match(D, m_Select(m_Value(C0), m_ConstantInt(0), m_ConstantInt(-1)))) {
|
||||||
Value *Cond = GET_SELECT_COND(D);
|
Value *C1 = 0;
|
||||||
if (match(C, m_Not(SELECT_MATCH(Cond))))
|
if (match(C, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, B, A);
|
return SelectInst::Create(C1, B, A);
|
||||||
if (match(A, m_Not(SELECT_MATCH(Cond))))
|
if (match(A, m_Not(SELECT_MATCH(C1, 0, -1))) && C1 == C0)
|
||||||
return SelectInst::Create(Cond, B, C);
|
return SelectInst::Create(C1, B, C);
|
||||||
}
|
}
|
||||||
#undef SELECT_MATCH
|
#undef SELECT_MATCH
|
||||||
#undef GET_SELECT_COND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
|
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
|
||||||
|
Reference in New Issue
Block a user