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

JIT: Fix cross crossgen comparison failures #112078

Merged
merged 5 commits into from
Feb 3, 2025
Merged
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
10 changes: 2 additions & 8 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,15 +1195,9 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,

/* Check for an addition of a constant */

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

/* We're adding a constant */

cns += op2->AsIntConCommon()->IconValue();
Expand Down
35 changes: 27 additions & 8 deletions src/coreclr/jit/likelyclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ struct LikelyClassMethodHistogramEntry
//
struct LikelyClassMethodHistogram
{
LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount);
LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount, bool int32Data = false);

template <typename ElemType>
void LikelyClassMethodHistogramInner(ElemType* histogramEntries, unsigned entryCount);

// Sum of counts from all entries in the histogram. This includes "unknown" entries which are not captured in
// m_histogram
Expand All @@ -61,8 +64,22 @@ struct LikelyClassMethodHistogram
// Arguments:
// histogramEntries - pointer to the table portion of a ClassProfile* object (see corjit.h)
// entryCount - number of entries in the table to examine
// int32Data - true if table entries are 32 bits
//
LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount)
LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount, bool int32Data)
{
if (int32Data)
{
LikelyClassMethodHistogramInner<int>((int*)histogramEntries, entryCount);
}
else
{
LikelyClassMethodHistogramInner<INT_PTR>(histogramEntries, entryCount);
}
}

template <typename ElemType>
void LikelyClassMethodHistogram::LikelyClassMethodHistogramInner(ElemType* histogramEntries, unsigned entryCount)
{
m_unknownHandles = 0;
m_totalCount = 0;
Expand All @@ -76,8 +93,7 @@ LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries
}

m_totalCount++;

INT_PTR currentEntry = histogramEntries[k];
INT_PTR currentEntry = (INT_PTR)histogramEntries[k];

bool found = false;
unsigned h = 0;
Expand Down Expand Up @@ -385,15 +401,18 @@ extern "C" DLLEXPORT UINT32 WINAPI getLikelyValues(LikelyValueRecord*
continue;

// We currently re-use existing infrastructure for type handles for simplicity.

const bool isHistogramCount =
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramIntCount) ||
//
const bool isIntHistogramCount =
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramIntCount);
const bool isLongHistogramCount =
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramLongCount);
const bool isHistogramCount = isIntHistogramCount || isLongHistogramCount;

if (isHistogramCount && (schema[i].Count == 1) && ((i + 1) < countSchemaItems) &&
(schema[i + 1].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogram))
{
LikelyClassMethodHistogram h((INT_PTR*)(pInstrumentationData + schema[i + 1].Offset), schema[i + 1].Count);
LikelyClassMethodHistogram h((INT_PTR*)(pInstrumentationData + schema[i + 1].Offset), schema[i + 1].Count,
isIntHistogramCount);
LikelyClassMethodHistogramEntry sortedEntries[HISTOGRAM_MAX_SIZE_COUNT];

if (h.countHistogramElements == 0)
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/jit/scev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@

#include "jitpch.h"

ScevConstant::ScevConstant(var_types type, int64_t value)
: Scev(ScevOper::Constant, type)
{
if (genTypeSize(type) == 4)
{
Value = (int32_t)value;
}
else
{
Value = value;
}
}

//------------------------------------------------------------------------
// GetConstantValue: If this SSA use refers to a constant, then fetch that
// constant.
Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/jit/scev.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ struct Scev

struct ScevConstant : Scev
{
ScevConstant(var_types type, int64_t value)
: Scev(ScevOper::Constant, type)
, Value(value)
{
}
ScevConstant(var_types type, int64_t value);

int64_t Value;
};
Expand Down
Loading