Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete GT_CNS_LNG #85951

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ bool IntegralRange::Contains(int64_t value) const
}

case GT_CNS_INT:
#ifndef TARGET_64BIT
if (node->TypeIs(TYP_LONG))
{
// TODO-CnsLng: delete this zero-diff quirk.
break;
}
#endif // !TARGET_64BIT
if (node->IsIntegralConst(0) || node->IsIntegralConst(1))
{
return {SymbolicIntegerValue::Zero, SymbolicIntegerValue::One};
Expand Down Expand Up @@ -990,12 +997,12 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
{
if (op1->gtGetOp2()->IsCnsIntOrI())
{
offset += op1->gtGetOp2()->AsIntCon()->gtIconVal;
offset += op1->gtGetOp2()->AsIntCon()->IconValue();
op1 = op1->gtGetOp1()->gtEffectiveVal(/* commaOnly */ true);
}
else if (op1->gtGetOp1()->IsCnsIntOrI())
{
offset += op1->gtGetOp1()->AsIntCon()->gtIconVal;
offset += op1->gtGetOp1()->AsIntCon()->IconValue();
op1 = op1->gtGetOp2()->gtEffectiveVal(/* commaOnly */ true);
}
else
Expand Down Expand Up @@ -1114,7 +1121,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
assertion.op2.kind = O2K_CONST_INT;
}

if (op2->gtOper != GT_CNS_INT)
if (!op2->IsCnsIntOrI())
{
goto DONE_ASSERTION; // Don't make an assertion
}
Expand All @@ -1129,7 +1136,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
assertion.op1.lcl.lclNum = lclNum;
assertion.op1.vn = optConservativeNormalVN(op1);
assertion.op1.lcl.ssaNum = op1->AsLclVarCommon()->GetSsaNum();
assertion.op2.u1.iconVal = op2->AsIntCon()->gtIconVal;
assertion.op2.u1.iconVal = op2->AsIntCon()->IconValue();
assertion.op2.vn = optConservativeNormalVN(op2);
assertion.op2.SetIconFlag(op2->GetIconHandleFlag());

Expand Down Expand Up @@ -1164,16 +1171,18 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
assert(op2->IsIntegralConst(0));
op2Kind = O2K_ZEROOBJ;
}
#ifndef TARGET_64BIT
else if (op1->TypeIs(TYP_LONG))
SingleAccretion marked this conversation as resolved.
Show resolved Hide resolved
{
op2Kind = O2K_CONST_LONG;
}
#endif // !TARGET_64BIT
else
{
op2Kind = O2K_CONST_INT;
}
goto CNS_COMMON;

case GT_CNS_LNG:
op2Kind = O2K_CONST_LONG;
goto CNS_COMMON;

case GT_CNS_DBL:
op2Kind = O2K_CONST_DOUBLE;
goto CNS_COMMON;
Expand All @@ -1200,9 +1209,9 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
assertion.op2.lconVal = 0;
assertion.op2.vn = optConservativeNormalVN(op2);

if (op2->gtOper == GT_CNS_INT)
if (op2->IsCnsIntOrI())
{
ssize_t iconVal = op2->AsIntCon()->gtIconVal;
ssize_t iconVal = op2->AsIntCon()->IconValue();

if (varTypeIsSmall(lclVar))
{
Expand All @@ -1211,7 +1220,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,

#ifdef TARGET_ARM
// Do not Constant-Prop large constants for ARM
// TODO-CrossBitness: we wouldn't need the cast below if GenTreeIntCon::gtIconVal had
// TODO-CrossBitness: we wouldn't need the cast below if GenTreeIntCon::IconValue() had
// target_ssize_t type.
if (!codeGen->validImmForMov((target_ssize_t)iconVal))
{
Expand All @@ -1222,9 +1231,9 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
assertion.op2.u1.iconVal = iconVal;
assertion.op2.SetIconFlag(op2->GetIconHandleFlag(), op2->AsIntCon()->gtFieldSeq);
}
else if (op2->gtOper == GT_CNS_LNG)
else if (op2->gtOper == GT_CNS_INT)
{
assertion.op2.lconVal = op2->AsLngCon()->gtLconVal;
assertion.op2.lconVal = op2->AsIntCon()->IntegralValue();
}
else
{
Expand Down Expand Up @@ -1462,22 +1471,12 @@ bool Compiler::optIsTreeKnownIntValue(bool vnBased, GenTree* tree, ssize_t* pCon
// Is Local assertion prop?
if (!vnBased)
{
if (tree->OperGet() == GT_CNS_INT)
if (tree->IsCnsIntOrI())
{
*pConstant = tree->AsIntCon()->IconValue();
*pFlags = tree->GetIconHandleFlag();
return true;
}
#ifdef TARGET_64BIT
// Just to be clear, get it from gtLconVal rather than
// overlapping gtIconVal.
else if (tree->OperGet() == GT_CNS_LNG)
{
*pConstant = tree->AsLngCon()->gtLconVal;
*pFlags = tree->GetIconHandleFlag();
return true;
}
#endif
return false;
}

Expand Down Expand Up @@ -2180,13 +2179,13 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
}

// Look for a call to an IsInstanceOf helper compared to a nullptr
if ((op2->gtOper != GT_CNS_INT) && (op1->gtOper == GT_CNS_INT))
if (!op2->IsCnsIntOrI() && op1->IsCnsIntOrI())
{
std::swap(op1, op2);
}
// Validate op1 and op2
if ((op1->gtOper != GT_CALL) || (op1->AsCall()->gtCallType != CT_HELPER) || (op1->TypeGet() != TYP_REF) || // op1
(op2->gtOper != GT_CNS_INT) || (op2->AsIntCon()->gtIconVal != 0)) // op2
!op2->IsCnsIntOrI() || (op2->AsIntCon()->IconValue() != 0)) // op2
{
return NO_ASSERTION_INDEX;
}
Expand Down Expand Up @@ -4040,14 +4039,14 @@ GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenT
}

// For Local AssertionProp we only can fold when op2 is a GT_CNS_INT
if (op2->gtOper != GT_CNS_INT)
if (!op2->IsCnsIntOrI())
{
return nullptr;
}

optOp1Kind op1Kind = O1K_LCLVAR;
optOp2Kind op2Kind = O2K_CONST_INT;
ssize_t cnsVal = op2->AsIntCon()->gtIconVal;
ssize_t cnsVal = op2->AsIntCon()->IconValue();
var_types cmpType = op1->TypeGet();

// Don't try to fold/optimize Floating Compares; there are multiple zero values.
Expand Down Expand Up @@ -4105,8 +4104,8 @@ GenTree* Compiler::optAssertionPropLocal_RelOp(ASSERT_VALARG_TP assertions, GenT
foldResult = !foldResult;
}

op2->AsIntCon()->gtIconVal = foldResult;
op2->gtType = TYP_INT;
op2->gtType = TYP_INT;
op2->AsIntCon()->SetIconValue(foldResult);

return optAssertionProp_Update(op2, tree, stmt);
}
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/jit/clrjit.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Documentation for VS debugger format specifiers: https://docs.microsoft.com/en-u
<DisplayString>{gtTreeID, d}: [{gtOper,en}, {gtType,en}]</DisplayString>
</Type>
<Type Name="GenTreeIntCon">
<DisplayString>{gtTreeID, d}: [IntCon={((GenTreeIntCon*)this)-&gt;gtIconVal, d}]</DisplayString>
<DisplayString>{gtTreeID, d}: [IntCon={((GenTreeIntCon*)this)-&gt;m_value, d}]</DisplayString>
</Type>
<Type Name="GenTreeDblCon">
<DisplayString>{gtTreeID, d}: [DblCon={((GenTreeDblCon*)this)-&gt;gtDconVal, g}]</DisplayString>
Expand All @@ -54,9 +54,6 @@ Documentation for VS debugger format specifiers: https://docs.microsoft.com/en-u
<Type Name="GenTreeVecCon">
<DisplayString>CNS_VEC</DisplayString>
</Type>
<Type Name="GenTreeLngCon">
<DisplayString>{gtTreeID, d}: [LngCon={((GenTreeLngCon*)this)-&gt;gtLconVal, l}]</DisplayString>
</Type>
<Type Name="GenTreeOp">
<DisplayString Condition="this->gtOper==GT_CAST">{gtTreeID, d}: [{((GenTreeCast*)this)-&gt;gtCastType,en} &lt;- {((GenTreeUnOp*)this)-&gt;gtOp1-&gt;gtType,en}]</DisplayString>
<DisplayString Condition="this->gtOper==GT_HWINTRINSIC">{gtTreeID, d}: [{((GenTreeHWIntrinsic*)this)-&gt;gtHWIntrinsicId,en}, {gtType,en}]</DisplayString>
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
{
// relocatable values tend to come down as a CNS_INT of native int type
// so the line between these two opcodes is kind of blurry
GenTreeIntConCommon* con = tree->AsIntConCommon();
ssize_t cnsVal = con->IconValue();
GenTreeIntCon* con = tree->AsIntCon();
ssize_t cnsVal = con->IconValue();

emitAttr attr = emitActualTypeSize(targetType);

Expand Down Expand Up @@ -397,7 +397,7 @@ void CodeGen::genLclHeap(GenTree* tree)
assert(size->isContained());

// If amount is zero then return null in regCnt
size_t amount = size->AsIntCon()->gtIconVal;
size_t amount = size->AsIntCon()->IconValue();
if (amount == 0)
{
instGen_Set_Reg_To_Zero(EA_PTRSIZE, regCnt);
Expand Down Expand Up @@ -436,7 +436,7 @@ void CodeGen::genLclHeap(GenTree* tree)
if (size->IsCnsIntOrI())
{
// 'amount' is the total number of bytes to localloc to properly STACK_ALIGN
target_size_t amount = (target_size_t)size->AsIntCon()->gtIconVal;
target_size_t amount = (target_size_t)size->AsIntCon()->IconValue();
amount = AlignUp(amount, STACK_ALIGN);

// For small allocations we will generate up to four push instructions (either 2 or 4, exactly,
Expand Down Expand Up @@ -937,7 +937,7 @@ void CodeGen::genCodeForShiftLong(GenTree* tree)

assert(shiftBy->isContainedIntOrIImmed());

unsigned count = (unsigned)shiftBy->AsIntConCommon()->IconValue();
unsigned count = (unsigned)shiftBy->AsIntCon()->IconValue();

regNumber regResult = (oper == GT_LSH_HI) ? regHi : regLo;

Expand Down
26 changes: 12 additions & 14 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2649,7 +2649,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree)
opt = ShiftOpToInsOpts(op2->gtOper);

emit->emitIns_R_R_R_I(ins, emitActualTypeSize(tree), targetReg, a->GetRegNum(), b->GetRegNum(),
c->AsIntConCommon()->IconValue(), opt);
c->AsIntCon()->IconValue(), opt);

genProduceReg(tree);
return;
Expand Down Expand Up @@ -3066,7 +3066,7 @@ void CodeGen::genLclHeap(GenTree* tree)
assert(size->isContained());

// If amount is zero then return null in targetReg
amount = size->AsIntCon()->gtIconVal;
amount = size->AsIntCon()->IconValue();
if (amount == 0)
{
instGen_Set_Reg_To_Zero(EA_PTRSIZE, targetReg);
Expand Down Expand Up @@ -3423,7 +3423,7 @@ void CodeGen::genCodeForNegNot(GenTree* tree)
GenTree* b = op1->gtGetOp2();
genConsumeRegs(op1);
GetEmitter()->emitIns_R_R_I(ins, emitActualTypeSize(tree), targetReg, a->GetRegNum(),
b->AsIntConCommon()->IntegralValue(), ShiftOpToInsOpts(oper));
b->AsIntCon()->IntegralValue(), ShiftOpToInsOpts(oper));
}
break;

Expand Down Expand Up @@ -3892,7 +3892,7 @@ void CodeGen::genLockedInstructions(GenTreeOp* treeNode)
{
// Even though INS_add is specified here, the encoder will choose either
// an INS_add or an INS_sub and encode the immediate as a positive value
genInstrWithConstant(INS_add, dataSize, storeDataReg, loadReg, data->AsIntConCommon()->IconValue(),
genInstrWithConstant(INS_add, dataSize, storeDataReg, loadReg, data->AsIntCon()->IconValue(),
REG_NA);
}
else
Expand Down Expand Up @@ -4021,7 +4021,7 @@ void CodeGen::genCodeForCmpXchg(GenTreeCmpXchg* treeNode)
else
{
GetEmitter()->emitIns_R_I(INS_cmp, emitActualTypeSize(treeNode), targetReg,
comparand->AsIntConCommon()->IconValue());
comparand->AsIntCon()->IconValue());
GetEmitter()->emitIns_J(INS_bne, labelCompareFail);
}
}
Expand Down Expand Up @@ -4559,7 +4559,7 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)

if (op2->isContainedIntOrIImmed())
{
GenTreeIntConCommon* intConst = op2->AsIntConCommon();
GenTreeIntCon* intConst = op2->AsIntCon();

regNumber op1Reg = op1->GetRegNum();

Expand Down Expand Up @@ -4599,8 +4599,7 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
assert(shiftOp2->isContained());

emit->emitIns_R_R_I(ins, cmpSize, op1->GetRegNum(), shiftOp1->GetRegNum(),
shiftOp2->AsIntConCommon()->IntegralValue(),
ShiftOpToInsOpts(oper));
shiftOp2->AsIntCon()->IntegralValue(), ShiftOpToInsOpts(oper));
}
break;

Expand All @@ -4621,7 +4620,7 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
assert(op2->gtGetOp2()->isContained());

emit->emitIns_R_R_I(ins, cmpSize, op1->GetRegNum(), op2->gtGetOp1()->GetRegNum(),
op2->gtGetOp2()->AsIntConCommon()->IntegralValue(), ShiftOpToInsOpts(oper));
op2->gtGetOp2()->AsIntCon()->IntegralValue(), ShiftOpToInsOpts(oper));
break;

default:
Expand Down Expand Up @@ -4687,7 +4686,7 @@ void CodeGen::genCodeForCCMP(GenTreeCCMP* ccmp)

if (op2->isContainedIntOrIImmed())
{
GenTreeIntConCommon* intConst = op2->AsIntConCommon();
GenTreeIntCon* intConst = op2->AsIntCon();
emit->emitIns_R_I_FLAGS_COND(INS_ccmp, cmpSize, srcReg1, (int)intConst->IconValue(), ccmp->gtFlagsVal, insCond);
}
else
Expand Down Expand Up @@ -4865,12 +4864,11 @@ void CodeGen::genCodeForJumpCompare(GenTreeOpCC* tree)

if (tree->OperIs(GT_JTEST))
{
ssize_t compareImm = op2->AsIntCon()->IconValue();

assert(isPow2(((size_t)compareImm)));
uint64_t compareImm = op2->AsIntCon()->IntegralValueUnsigned();
assert(isPow2(compareImm));

instruction ins = (cc.GetCode() == GenCondition::EQ) ? INS_tbz : INS_tbnz;
int imm = genLog2((size_t)compareImm);
int imm = genLog2(compareImm);

GetEmitter()->emitIns_J_R_I(ins, attr, compiler->compCurBB->GetJumpDest(), reg, imm);
}
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ void CodeGen::genPutArgStk(GenTreePutArgStk* treeNode)
if (source->isContained())
{
#ifdef TARGET_ARM64
assert(source->OperGet() == GT_CNS_INT);
assert(source->AsIntConCommon()->IconValue() == 0);
assert(source->IsCnsIntOrI());
assert(source->AsIntCon()->IconValue() == 0);

emit->emitIns_S_R(storeIns, storeAttr, REG_ZR, varNumOut, argOffsetOut);
#else // !TARGET_ARM64
Expand Down Expand Up @@ -1580,7 +1580,7 @@ void CodeGen::genCodeForShift(GenTree* tree)
else
{
unsigned immWidth = emitter::getBitWidth(size); // For ARM64, immWidth will be set to 32 or 64
unsigned shiftByImm = (unsigned)shiftBy->AsIntCon()->gtIconVal & (immWidth - 1);
unsigned shiftByImm = (unsigned)shiftBy->AsIntCon()->IconValue() & (immWidth - 1);
GetEmitter()->emitIns_R_R_I(ins, size, dstReg, operand->GetRegNum(), shiftByImm);
}

Expand Down Expand Up @@ -4699,7 +4699,7 @@ void CodeGen::genLeaInstruction(GenTreeAddrMode* lea)
{
// Handle LEA with "contained" BFIZ
assert(scale == 0);
scale = (DWORD)index->gtGetOp2()->AsIntConCommon()->IconValue();
scale = (DWORD)index->gtGetOp2()->AsIntCon()->IconValue();
index = index->gtGetOp1()->gtGetOp1();
}
else if (index->OperIs(GT_CAST))
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,18 +1113,18 @@ bool CodeGen::genCreateAddrMode(

/* Check for an addition of a constant */

if (op2->IsIntCnsFitsInI32() && (op2->gtType != TYP_REF) && FitsIn<INT32>(cns + op2->AsIntConCommon()->IconValue()))
if (op2->IsIntCnsFitsInI32() && (op2->gtType != TYP_REF) && FitsIn<INT32>(cns + op2->AsIntCon()->IconValue()))
{
// We should not be building address modes out of non-foldable constants
if (!op2->AsIntConCommon()->ImmedValCanBeFolded(compiler, addr->OperGet()))
if (!op2->AsIntCon()->ImmedValCanBeFolded(compiler, addr->OperGet()))
{
assert(compiler->opts.compReloc);
return false;
}

/* We're adding a constant */

cns += op2->AsIntConCommon()->IconValue();
cns += op2->AsIntCon()->IconValue();

#if defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
if (cns == 0)
Expand Down Expand Up @@ -1386,7 +1386,7 @@ bool CodeGen::genCreateAddrMode(
}
else if (index->IsIntCnsFitsInI32())
{
ssize_t constantIndex = index->AsIntConCommon()->IconValue() * indexScale;
ssize_t constantIndex = index->AsIntCon()->IconValue() * indexScale;
if (constantIndex == 0)
{
// while scale is a non-zero constant, the actual index is zero so drop it
Expand Down Expand Up @@ -7471,7 +7471,7 @@ const char* CodeGen::siStackVarName(size_t offs, size_t size, unsigned reg, unsi
//
GenTreeIntCon CodeGen::intForm(var_types type, ssize_t value)
{
GenTreeIntCon i(type, value);
GenTreeIntCon i(type, value, nullptr);
i.SetRegNum(REG_NA);
return i;
}
Expand Down
Loading
Loading