Skip to content

Commit

Permalink
Implement AND_NOT for AAarch
Browse files Browse the repository at this point in the history
  • Loading branch information
SingleAccretion committed Oct 5, 2021
1 parent 3a7abbd commit bc94fa5
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/coreclr/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ void CodeGen::genCodeForBinary(GenTreeOp* treeNode)
var_types targetType = treeNode->TypeGet();
emitter* emit = GetEmitter();

assert(oper == GT_ADD || oper == GT_SUB || oper == GT_MUL || oper == GT_ADD_LO || oper == GT_ADD_HI ||
oper == GT_SUB_LO || oper == GT_SUB_HI || oper == GT_OR || oper == GT_XOR || oper == GT_AND);
assert(treeNode->OperIs(GT_ADD, GT_SUB, GT_MUL, GT_ADD_LO, GT_ADD_HI, GT_SUB_LO, GT_SUB_HI, GT_OR, GT_XOR, GT_AND,
GT_AND_NOT));

GenTree* op1 = treeNode->gtGetOp1();
GenTree* op2 = treeNode->gtGetOp2();
Expand Down Expand Up @@ -664,6 +664,9 @@ instruction CodeGen::genGetInsForOper(genTreeOps oper, var_types type)
case GT_AND:
ins = INS_AND;
break;
case GT_AND_NOT:
ins = INS_bic;
break;
case GT_MUL:
ins = INS_MUL;
break;
Expand Down
11 changes: 8 additions & 3 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ void CodeGen::genCodeForMulHi(GenTreeOp* treeNode)
genProduceReg(treeNode);
}

// Generate code for ADD, SUB, MUL, DIV, UDIV, AND, OR and XOR
// Generate code for ADD, SUB, MUL, DIV, UDIV, AND, AND_NOT, OR and XOR
// This method is expected to have called genConsumeOperands() before calling it.
void CodeGen::genCodeForBinary(GenTreeOp* treeNode)
{
Expand All @@ -1822,8 +1822,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* treeNode)
var_types targetType = treeNode->TypeGet();
emitter* emit = GetEmitter();

assert(oper == GT_ADD || oper == GT_SUB || oper == GT_MUL || oper == GT_DIV || oper == GT_UDIV || oper == GT_AND ||
oper == GT_OR || oper == GT_XOR);
assert(treeNode->OperIs(GT_ADD, GT_SUB, GT_MUL, GT_DIV, GT_UDIV, GT_AND, GT_AND_NOT, GT_OR, GT_XOR));

GenTree* op1 = treeNode->gtGetOp1();
GenTree* op2 = treeNode->gtGetOp2();
Expand All @@ -1842,6 +1841,9 @@ void CodeGen::genCodeForBinary(GenTreeOp* treeNode)
case GT_AND:
ins = INS_ands;
break;
case GT_AND_NOT:
ins = INS_bics;
break;
default:
noway_assert(!"Unexpected BinaryOp with GTF_SET_FLAGS set");
}
Expand Down Expand Up @@ -3115,6 +3117,9 @@ instruction CodeGen::genGetInsForOper(genTreeOps oper, var_types type)
case GT_AND:
ins = INS_and;
break;
case GT_AND_NOT:
ins = INS_bic;
break;
case GT_DIV:
ins = INS_sdiv;
break;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode)
case GT_OR:
case GT_XOR:
case GT_AND:
case GT_AND_NOT:
assert(varTypeIsIntegralOrI(treeNode));

FALLTHROUGH;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/emitarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8095,7 +8095,7 @@ regNumber emitter::emitInsTernary(instruction ins, emitAttr attr, GenTree* dst,
if (dst->gtSetFlags())
{
assert((ins == INS_add) || (ins == INS_adc) || (ins == INS_sub) || (ins == INS_sbc) || (ins == INS_and) ||
(ins == INS_orr) || (ins == INS_eor) || (ins == INS_orn));
(ins == INS_orr) || (ins == INS_eor) || (ins == INS_orn) || (ins == INS_bic));
flags = INS_FLAGS_SET;
}

Expand Down
51 changes: 49 additions & 2 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ GenTree* Lowering::LowerNode(GenTree* node)
case GT_AND:
case GT_OR:
case GT_XOR:
ContainCheckBinary(node->AsOp());
break;
return LowerBinaryArithmeticCommon(node->AsOp());

case GT_MUL:
case GT_MULHI:
Expand Down Expand Up @@ -5098,6 +5097,54 @@ GenTree* Lowering::LowerAdd(GenTreeOp* node)
return nullptr;
}

//------------------------------------------------------------------------
// LowerBinaryArithmeticCommon: lowers the given binary arithmetic node.
//
// Recognizes opportunities for using target-independent "combined" nodes
// (currently AND_NOT on ARMArch). Calls the target-specific "LowerBinaryArithmetic"
// method, which checks for more nodes and containment.
//
// Arguments:
// node - the arithmetic node to lower
//
// Returns:
// The next node to lower.
//
GenTree* Lowering::LowerBinaryArithmeticCommon(GenTreeOp* node)
{
// TODO-CQ-XArch: support BMI2 "andn" in codegen and condition
// this logic on the support for the instruction set on XArch.
CLANG_FORMAT_COMMENT_ANCHOR;

#ifdef TARGET_ARMARCH
if (comp->opts.OptimizationEnabled() && node->OperIs(GT_AND))
{
GenTree* opNode = nullptr;
GenTree* notNode = nullptr;
if (node->gtGetOp1()->OperIs(GT_NOT))
{
notNode = node->gtGetOp1();
opNode = node->gtGetOp2();
}
else if (node->gtGetOp2()->OperIs(GT_NOT))
{
notNode = node->gtGetOp2();
opNode = node->gtGetOp1();
}

if (notNode != nullptr)
{
node->gtOp1 = opNode;
node->gtOp2 = notNode->AsUnOp()->gtGetOp1();
node->ChangeOper(GT_AND_NOT);
BlockRange().Remove(notNode);
}
}
#endif // TARGET_ARMARCH

return LowerBinaryArithmetic(node);
}

//------------------------------------------------------------------------
// LowerUnsignedDivOrMod: Lowers a GT_UDIV/GT_UMOD node.
//
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class Lowering final : public Phase
void LowerStoreIndir(GenTreeStoreInd* node);
GenTree* LowerAdd(GenTreeOp* node);
GenTree* LowerMul(GenTreeOp* mul);
GenTree* LowerBinaryArithmeticCommon(GenTreeOp* node);
GenTree* LowerBinaryArithmetic(GenTreeOp* node);
bool LowerUnsignedDivOrMod(GenTreeOp* divMod);
GenTree* LowerConstIntDivOrMod(GenTree* node);
GenTree* LowerSignedDivOrMod(GenTree* node);
Expand Down
19 changes: 19 additions & 0 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,25 @@ GenTree* Lowering::LowerMul(GenTreeOp* mul)
return mul->gtNext;
}

// LowerBinaryArithmetic: lowers the given binary arithmetic node.
//
// Currently only performs containment checks.
//
// TODO-CQ-ARMArch: take advantage of "madd" and "msub" here.
//
// Arguments:
// node - the arithmetic node to lower
//
// Returns:
// The next node to lower.
//
GenTree* Lowering::LowerBinaryArithmetic(GenTreeOp* node)
{
ContainCheckBinary(node);

return node->gtNext;
}

//------------------------------------------------------------------------
// LowerBlockStore: Lower a block store node
//
Expand Down
19 changes: 19 additions & 0 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ GenTree* Lowering::LowerMul(GenTreeOp* mul)
return mul->gtNext;
}

// LowerBinaryArithmetic: lowers the given binary arithmetic node.
//
// Currently only performs containment checks.
//
// TODO-CQ-XArch: take advantage of the BMI instructions here.
//
// Arguments:
// node - the arithmetic node to lower
//
// Returns:
// The next node to lower.
//
GenTree* Lowering::LowerBinaryArithmetic(GenTreeOp* node)
{
ContainCheckBinary(node);

return node->gtNext;
}

//------------------------------------------------------------------------
// LowerBlockStore: Lower a block store node
//
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsraarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ int LinearScan::BuildNode(GenTree* tree)
FALLTHROUGH;

case GT_AND:
case GT_AND_NOT:
case GT_OR:
case GT_XOR:
case GT_LSH:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lsraarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ int LinearScan::BuildNode(GenTree* tree)
FALLTHROUGH;

case GT_AND:
case GT_AND_NOT:
case GT_OR:
case GT_XOR:
case GT_LSH:
Expand Down

0 comments on commit bc94fa5

Please sign in to comment.