Skip to content

Commit 2a46490

Browse files
author
Quantum Hu
committed
Update to not modify codegen based on set flags variable
1 parent 18839c0 commit 2a46490

File tree

5 files changed

+10
-33
lines changed

5 files changed

+10
-33
lines changed

src/coreclr/jit/codegenarm.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,14 +1271,7 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
12711271
{
12721272
assert(!varTypeIsFloating(op2Type));
12731273
var_types cmpType = (op1Type == op2Type) ? op1Type : TYP_INT;
1274-
1275-
// When comparing to constant zero, and descendant node (op1) set the flags, we can skip emitting the cmp
1276-
bool skipGenCmp = ((op1->gtFlags & GTF_SET_FLAGS) != 0) && op2->IsIntegralConst(0);
1277-
1278-
if (!skipGenCmp)
1279-
{
1280-
emit->emitInsBinary(INS_cmp, emitTypeSize(cmpType), op1, op2);
1281-
}
1274+
emit->emitInsBinary(INS_cmp, emitTypeSize(cmpType), op1, op2);
12821275
}
12831276

12841277
// Are we evaluating this into a register?

src/coreclr/jit/codegenarm64.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4992,20 +4992,9 @@ void CodeGen::genCodeForJumpCompare(GenTreeOpCC* tree)
49924992
{
49934993
assert(op2->IsIntegralConst(0));
49944994

4995-
// It's possible the descendant node (op1) set the flags. If so, we don't need to compare again
4996-
bool genBranchOnly = (op1->gtFlags & GTF_SET_FLAGS) != 0;
4995+
instruction ins = (cc.GetCode() == GenCondition::EQ) ? INS_cbz : INS_cbnz;
49974996

4998-
instruction ins;
4999-
if (!genBranchOnly)
5000-
{
5001-
ins = (cc.GetCode() == GenCondition::EQ) ? INS_cbz : INS_cbnz;
5002-
GetEmitter()->emitIns_J_R(ins, attr, compiler->compCurBB->GetTrueTarget(), reg);
5003-
}
5004-
else
5005-
{
5006-
ins = (cc.GetCode() == GenCondition::EQ) ? INS_beq : INS_bne;
5007-
GetEmitter()->emitIns_J(ins, compiler->compCurBB->GetTrueTarget());
5008-
}
4997+
GetEmitter()->emitIns_J_R(ins, attr, compiler->compCurBB->GetTrueTarget(), reg);
50094998
}
50104999

50115000
// If we cannot fall into the false target, emit a jump to it

src/coreclr/jit/gentree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19951,8 +19951,8 @@ bool GenTree::SupportsSettingZeroFlag()
1995119951
return true;
1995219952
}
1995319953
#endif
19954-
#elif defined(TARGET_ARM64)
19955-
if (OperIs(GT_AND))
19954+
#elif defined(TARGET_ARM64) || defined(TARGET_ARM)
19955+
if (OperIs(GT_AND, GT_AND_NOT))
1995619956
{
1995719957
return true;
1995819958
}

src/coreclr/jit/lower.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4314,9 +4314,10 @@ GenTree* Lowering::LowerJTrue(GenTreeOp* jtrue)
43144314
genTreeOps newOper = GT_COUNT;
43154315
GenCondition cc;
43164316

4317-
if (cond->OperIs(GT_EQ, GT_NE) && relopOp2->IsIntegralConst(0))
4317+
if (cond->OperIs(GT_EQ, GT_NE) && relopOp2->IsIntegralConst(0) && !relopOp1->SupportsSettingZeroFlag())
43184318
{
43194319
// Codegen will use cbz or cbnz in codegen which do not affect the flag register
4320+
// However if relopOp1 can set flags, then we do not need to compare and branch, can just branch
43204321
newOper = GT_JCMP;
43214322
cc = GenCondition::FromRelop(cond);
43224323
}

src/coreclr/jit/morph.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8112,25 +8112,19 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
81128112
// ~a & c ==/!= 0
81138113
// where c is a constant
81148114
// The optimization could also take the form of a & ~c but the comparison would have to switch between EQ to NE/NE to EQ
8115-
if (op1->OperIs(GT_AND) && varTypeIsIntegral(op1) && op2->IsIntegralConst())
8115+
if (op1->OperIs(GT_AND) && varTypeIsIntegral(op1) && op2->IsCnsIntOrI())
81168116
{
81178117
GenTree* andOp1 = op1->AsOp()->gtOp1;
81188118
GenTree* andOp2 = op1->AsOp()->gtOp2;
81198119

8120-
ssize_t cnsVal = op2->AsIntCon()->IconValue();
8121-
8122-
if (andOp1->TypeIs(TYP_INT, TYP_LONG) && andOp2->IsIntegralConst() && andOp2->AsIntCon()->IconValue() == cnsVal)
8120+
if (andOp1->TypeIs(TYP_INT) && GenTree::Compare(op2, andOp2))
81238121
{
81248122
// Want GT_AND to look like AND(NOT(a), c) ==/!= a. The non-matching constant must be the one wrapped in NOT node
81258123
// so 2nd andOp will be the constant, so 1st andOp will have the NOT
81268124
GenTree* tmpNode = andOp2;
81278125
op1->AsOp()->gtOp2 = gtNewOperNode(GT_NOT, andOp1->TypeGet(), andOp1);
81288126
op1->AsOp()->gtOp1 = tmpNode;
8129-
op2->AsIntConCommon()->SetIconValue(0);
8130-
#if defined(TARGET_ARM) || defined(TARGET_ARM64)
8131-
// If set for XARCH it will prevent ANDN instruction from being emitted
8132-
op1->gtFlags |= GTF_SET_FLAGS;
8133-
#endif
8127+
op2->BashToZeroConst(op2->gtType);
81348128
}
81358129
}
81368130
}

0 commit comments

Comments
 (0)