Skip to content

Commit 0bd2dbb

Browse files
EgorBoCopilotCopilot
authored
Remove -Wno-unused-function -Wno-tautological-compare -Wno-unused-value for clrjit projects (#128271)
We currently define the followings for the entire native code: - [ ] add_compile_options(-Wno-unused-variable) - [x] add_compile_options(-Wno-unused-value) - [x] add_compile_options(-Wno-unused-function) - [x] add_compile_options(-Wno-tautological-compare) - [ ] add_compile_options(-Wno-unknown-pragmas) my initial attempt to remove them all led to a very big diff so I decided to focus on JIT first. --------- Co-authored-by: EgorBo <egorbo@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent eb6a878 commit 0bd2dbb

9 files changed

Lines changed: 35 additions & 74 deletions

File tree

src/coreclr/jit/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ if (MSVC)
1616
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/permissive->)
1717
endif()
1818

19+
# The JIT enforces -Wunused-function, -Wtautological-compare and -Wunused-value
20+
# (overriding the repo-wide -Wno-* counterparts from configurecompiler.cmake) so
21+
# that dead helpers, always-true/always-false comparisons and discarded
22+
# expressions are caught early. Any helper or comparison that is only meaningful
23+
# under a target/DEBUG #ifdef must be guarded by the same condition.
24+
if (CLR_CMAKE_HOST_UNIX OR CLR_CMAKE_HOST_WASI)
25+
add_compile_options(-Wunused-function -Wtautological-compare -Wunused-value)
26+
endif()
27+
1928
function(create_standalone_jit)
2029

2130
set(oneValueArgs TARGET OS ARCH)

src/coreclr/jit/emitriscv64.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,18 +2882,6 @@ static unsigned UpperNBitsOfWordSignExtend(ssize_t word)
28822882
return UpperNBitsOfWord<MaskSize>(word + kSignExtend);
28832883
}
28842884

2885-
static unsigned UpperWordOfDoubleWord(ssize_t immediate)
2886-
{
2887-
return static_cast<unsigned>(immediate >> 32);
2888-
}
2889-
2890-
static unsigned LowerWordOfDoubleWord(ssize_t immediate)
2891-
{
2892-
static constexpr size_t kWordMask = WordMask(32);
2893-
2894-
return static_cast<unsigned>(immediate & kWordMask);
2895-
}
2896-
28972885
template <uint8_t UpperMaskSize, uint8_t LowerMaskSize>
28982886
static ssize_t DoubleWordSignExtend(ssize_t doubleWord)
28992887
{
@@ -2903,20 +2891,6 @@ static ssize_t DoubleWordSignExtend(ssize_t doubleWord)
29032891
return doubleWord + (kLowerSignExtend | kUpperSignExtend);
29042892
}
29052893

2906-
template <uint8_t UpperMaskSize>
2907-
static ssize_t UpperWordOfDoubleWordSingleSignExtend(ssize_t doubleWord)
2908-
{
2909-
static constexpr size_t kUpperSignExtend = static_cast<size_t>(1) << (31 - UpperMaskSize);
2910-
2911-
return UpperWordOfDoubleWord(doubleWord + kUpperSignExtend);
2912-
}
2913-
2914-
template <uint8_t UpperMaskSize, uint8_t LowerMaskSize>
2915-
static ssize_t UpperWordOfDoubleWordDoubleSignExtend(ssize_t doubleWord)
2916-
{
2917-
return UpperWordOfDoubleWord(DoubleWordSignExtend<UpperMaskSize, LowerMaskSize>(doubleWord));
2918-
}
2919-
29202894
/*static*/ unsigned emitter::TrimSignedToImm12(ssize_t imm12)
29212895
{
29222896
assert(isValidSimm12(imm12));
@@ -5690,7 +5664,7 @@ emitter::insExecutionCharacteristics emitter::getInsExecutionCharacteristics(ins
56905664
}
56915665

56925666
regNumber baseReg = id->idReg2();
5693-
if (baseReg != REG_SP || baseReg != REG_FP)
5667+
if ((baseReg != REG_SP) && (baseReg != REG_FP))
56945668
result.insLatency += PERFSCORE_LATENCY_1C; // assume non-stack load/stores are more likely to cache-miss
56955669

56965670
result.insThroughput += immediateBuildingCost;

src/coreclr/jit/emitxarch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ bool emitter::Is4ByteSSEInstruction(instruction ins) const
16651665
return !UseVEXEncoding() && EncodedBySSE38orSSE3A(ins);
16661666
}
16671667

1668+
#ifdef DEBUG
16681669
//------------------------------------------------------------------------
16691670
// isLowSIMDReg: Checks if a register is a register supported by any SIMD encoding
16701671
//
@@ -1681,6 +1682,7 @@ static bool isLowSimdReg(regNumber reg)
16811682
return (reg >= REG_XMM0) && (reg <= REG_XMM7);
16821683
#endif
16831684
}
1685+
#endif // DEBUG
16841686

16851687
//------------------------------------------------------------------------
16861688
// GetEmbRoundingMode: Get the rounding mode for embedded rounding

src/coreclr/jit/gentree.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10467,7 +10467,11 @@ bool GenTreeOp::UsesDivideByConstOptimized(Compiler* comp)
1046710467
if (isSignedDivide)
1046810468
{
1046910469
// If the divisor is the minimum representable integer value then the result is either 0 or 1
10470-
if ((divType == TYP_INT && divisorValue == INT_MIN) || (divType == TYP_LONG && divisorValue == INT64_MIN))
10470+
if ((divType == TYP_INT && divisorValue == INT_MIN)
10471+
#if defined(TARGET_64BIT)
10472+
|| (divType == TYP_LONG && divisorValue == INT64_MIN)
10473+
#endif
10474+
)
1047110475
{
1047210476
return true;
1047310477
}
@@ -32026,7 +32030,7 @@ NamedIntrinsic GenTreeHWIntrinsic::GetHWIntrinsicIdForCmpOp(Compiler* comp,
3202632030
}
3202732031
else if (isScalar)
3202832032
{
32029-
reverseCond ? NI_X86Base_CompareScalarNotLessThanOrEqual : NI_X86Base_CompareScalarGreaterThan;
32033+
id = reverseCond ? NI_X86Base_CompareScalarNotLessThanOrEqual : NI_X86Base_CompareScalarGreaterThan;
3203032034
}
3203132035
else
3203232036
{

src/coreclr/jit/hwintrinsic.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,46 +1661,6 @@ static bool impIsTableDrivenHWIntrinsic(NamedIntrinsic intrinsicId, HWIntrinsicC
16611661
return (category != HW_Category_Special) && !HWIntrinsicInfo::HasSpecialImport(intrinsicId);
16621662
}
16631663

1664-
//------------------------------------------------------------------------
1665-
// isSupportedBaseType
1666-
//
1667-
// Arguments:
1668-
// intrinsicId - HW intrinsic id
1669-
// baseJitType - Base JIT type of the intrinsic.
1670-
//
1671-
// Return Value:
1672-
// returns true if the baseType is supported for given intrinsic.
1673-
//
1674-
static bool isSupportedBaseType(NamedIntrinsic intrinsic, CorInfoType baseJitType)
1675-
{
1676-
if (baseJitType == CORINFO_TYPE_UNDEF)
1677-
{
1678-
return false;
1679-
}
1680-
1681-
var_types baseType = JitType2PreciseVarType(baseJitType);
1682-
1683-
// We don't actually check the intrinsic outside of the false case as we expect
1684-
// the exposed managed signatures are either generic and support all types
1685-
// or they are explicit and support the type indicated.
1686-
1687-
if (varTypeIsArithmetic(baseType))
1688-
{
1689-
return true;
1690-
}
1691-
1692-
#ifdef DEBUG
1693-
CORINFO_InstructionSet isa = HWIntrinsicInfo::lookupIsa(intrinsic);
1694-
#ifdef TARGET_XARCH
1695-
assert((isa == InstructionSet_Vector512) || (isa == InstructionSet_Vector256) || (isa == InstructionSet_Vector128));
1696-
#endif // TARGET_XARCH
1697-
#ifdef TARGET_ARM64
1698-
assert((isa == InstructionSet_Vector64) || (isa == InstructionSet_Vector128));
1699-
#endif // TARGET_ARM64
1700-
#endif // DEBUG
1701-
return false;
1702-
}
1703-
17041664
static bool isSupportedBaseType(NamedIntrinsic intrinsic, var_types baseType)
17051665
{
17061666
if (baseType == TYP_UNDEF)

src/coreclr/jit/ifconversion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ GenTree* OptIfConversionDsc::TryOptimizeSelect(GenTreeConditional* select)
742742
return nullptr;
743743
}
744744

745+
#ifdef TARGET_RISCV64
745746
struct IntConstSelectOper
746747
{
747748
genTreeOps oper;
@@ -794,6 +795,7 @@ static IntConstSelectOper MatchIntConstSelectValues(int64_t trueVal, int64_t fal
794795

795796
return {GT_NONE};
796797
}
798+
#endif // TARGET_RISCV64
797799

798800
//-----------------------------------------------------------------------------
799801
// TrySelectToCnsOpCond: Try to optimize:

src/coreclr/jit/importercalls.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4776,8 +4776,7 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
47764776
// This is now known to be a multi-dimension array with a constant dimension
47774777
// that is in range; we can expand it as an intrinsic.
47784778

4779-
impPopStack().val; // Pop the dim and array object; we already have a pointer to them.
4780-
impPopStack().val;
4779+
impPopStack(2); // Pop the dim and array object; we already have a pointer to them.
47814780

47824781
// Make sure there are no global effects in the array (such as it being a function
47834782
// call), so we can mark the generated indirection with GTF_IND_INVARIANT. In the

src/coreclr/jit/lower.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8157,8 +8157,11 @@ bool Lowering::TryLowerConstIntUDivOrUMod(GenTreeOp* divMod)
81578157
{
81588158
// If the divisor is greater or equal than 2^(N - 1) then the result is 1
81598159
// iff the dividend is greater or equal than the divisor.
8160-
if (((type == TYP_INT) && (divisorValue > (UINT32_MAX / 2))) ||
8161-
((type == TYP_LONG) && (divisorValue > (UINT64_MAX / 2))))
8160+
if (((type == TYP_INT) && (divisorValue > (UINT32_MAX / 2)))
8161+
#if defined(TARGET_64BIT)
8162+
|| ((type == TYP_LONG) && (divisorValue > (UINT64_MAX / 2)))
8163+
#endif
8164+
)
81628165
{
81638166
divMod->ChangeOper(GT_GE);
81648167
divMod->SetUnsigned();
@@ -8448,7 +8451,11 @@ bool Lowering::TryLowerConstIntDivOrMod(GenTree* node, GenTree** nextNode)
84488451

84498452
if (isDiv)
84508453
{
8451-
if ((type == TYP_INT && divisorValue == INT_MIN) || (type == TYP_LONG && divisorValue == INT64_MIN))
8454+
if ((type == TYP_INT && divisorValue == INT_MIN)
8455+
#if defined(TARGET_64BIT)
8456+
|| (type == TYP_LONG && divisorValue == INT64_MIN)
8457+
#endif
8458+
)
84528459
{
84538460
// If the divisor is the minimum representable integer value then we can use a compare,
84548461
// the result is 1 iff the dividend equals divisor.
@@ -10400,6 +10407,7 @@ static bool IsStoreCoalescingInvariantNode(Compiler* compiler, GenTree* node, bo
1040010407
return node->OperIs(GT_LCL_VAR) && !compiler->lvaVarAddrExposed(node->AsLclVar()->GetLclNum());
1040110408
}
1040210409

10410+
#if defined(TARGET_XARCH) || defined(TARGET_ARM64)
1040310411
//------------------------------------------------------------------------
1040410412
// TryGetStoreCoalescingConstantBits: get the raw bits for a constant used by store
1040510413
// coalescing.
@@ -10442,6 +10450,7 @@ static bool TryGetStoreCoalescingConstantBits(GenTree* value, uint64_t* bits)
1044210450

1044310451
return false;
1044410452
}
10453+
#endif // TARGET_XARCH || TARGET_ARM64
1044510454

1044610455
//------------------------------------------------------------------------
1044710456
// GetLoadStoreCoalescingData: given a STOREIND/IND node, get the data needed to perform

src/coreclr/jit/scev.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ ValueNumPair ScalarEvolutionContext::MaterializeVN(Scev* scev)
14691469
return Materialize(scev, false, nullptr, &vnp) ? vnp : ValueNumPair();
14701470
}
14711471

1472+
#ifdef DEBUG
14721473
//------------------------------------------------------------------------
14731474
// RelopEvaluationResultString: Convert a RelopEvaluationResult to a string.
14741475
//
@@ -1492,6 +1493,7 @@ static const char* RelopEvaluationResultString(RelopEvaluationResult result)
14921493
return "n/a";
14931494
}
14941495
}
1496+
#endif // DEBUG
14951497

14961498
//------------------------------------------------------------------------
14971499
// EvaluateRelop:

0 commit comments

Comments
 (0)