Skip to content

Commit 542a7df

Browse files
authoredAug 28, 2023
JIT: Remove TYP_BOOL (#90981)
TYP_BOOL servces no purpose but to confuse today. We try to use it in some cases to make assumptions about the value being 0/1, but this logic is not correct in the face of unnormalized booleans. This change remove TYP_BOOL replacing its uses by TYP_UBYTE. This fixes an issue where we forgot to handle TYP_BOOL. Fix #90798
1 parent 919be00 commit 542a7df

20 files changed

+21
-103
lines changed
 

‎src/coreclr/jit/assertionprop.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ bool IntegralRange::Contains(int64_t value) const
8181
{
8282
switch (type)
8383
{
84-
case TYP_BOOL:
8584
case TYP_UBYTE:
8685
case TYP_USHORT:
8786
return SymbolicIntegerValue::Zero;
@@ -113,7 +112,6 @@ bool IntegralRange::Contains(int64_t value) const
113112
{
114113
case TYP_BYTE:
115114
return SymbolicIntegerValue::ByteMax;
116-
case TYP_BOOL:
117115
case TYP_UBYTE:
118116
return SymbolicIntegerValue::UByteMax;
119117
case TYP_SHORT:
@@ -890,7 +888,6 @@ ssize_t Compiler::optCastConstantSmall(ssize_t iconVal, var_types smallType)
890888
case TYP_USHORT:
891889
return uint16_t(iconVal);
892890

893-
case TYP_BOOL:
894891
case TYP_UBYTE:
895892
return uint8_t(iconVal);
896893

@@ -2708,7 +2705,6 @@ GenTree* Compiler::optVNConstantPropOnTree(BasicBlock* block, GenTree* tree)
27082705
unreached();
27092706
break;
27102707

2711-
case TYP_BOOL:
27122708
case TYP_BYTE:
27132709
case TYP_UBYTE:
27142710
case TYP_SHORT:

‎src/coreclr/jit/codegenxarch.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6735,7 +6735,7 @@ void CodeGen::genCompareFloat(GenTree* treeNode)
67356735
if (((op1->gtGetContainedRegMask() | op2->gtGetContainedRegMask()) & targetRegMask) == 0)
67366736
{
67376737
instGen_Set_Reg_To_Zero(emitTypeSize(TYP_I_IMPL), targetReg);
6738-
targetType = TYP_BOOL; // just a tip for inst_SETCC that movzx is not needed
6738+
targetType = TYP_UBYTE; // just a tip for inst_SETCC that movzx is not needed
67396739
}
67406740
}
67416741
GetEmitter()->emitInsBinary(ins, cmpAttr, op1, op2);
@@ -6906,7 +6906,7 @@ void CodeGen::genCompareInt(GenTree* treeNode)
69066906
if (((op1->gtGetContainedRegMask() | op2->gtGetContainedRegMask()) & targetRegMask) == 0)
69076907
{
69086908
instGen_Set_Reg_To_Zero(emitTypeSize(TYP_I_IMPL), targetReg);
6909-
targetType = TYP_BOOL; // just a tip for inst_SETCC that movzx is not needed
6909+
targetType = TYP_UBYTE; // just a tip for inst_SETCC that movzx is not needed
69106910
}
69116911
}
69126912

‎src/coreclr/jit/compiler.h

-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ class LclVarDsc
558558
unsigned char lvIsSplit : 1; // Set if the argument is splited.
559559
#endif // defined(TARGET_RISCV64)
560560

561-
unsigned char lvIsBoolean : 1; // set if variable is boolean
562561
unsigned char lvSingleDef : 1; // variable has a single def. Used to identify ref type locals that can get type
563562
// updates
564563

‎src/coreclr/jit/ee_il_dll.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ inline var_types JITtype2varType(CorInfoType type)
174174
// see the definition of enum CorInfoType in file inc/corinfo.h
175175
TYP_UNDEF, // CORINFO_TYPE_UNDEF = 0x0,
176176
TYP_VOID, // CORINFO_TYPE_VOID = 0x1,
177-
TYP_BOOL, // CORINFO_TYPE_BOOL = 0x2,
177+
TYP_UBYTE, // CORINFO_TYPE_BOOL = 0x2,
178178
TYP_USHORT, // CORINFO_TYPE_CHAR = 0x3,
179179
TYP_BYTE, // CORINFO_TYPE_BYTE = 0x4,
180180
TYP_UBYTE, // CORINFO_TYPE_UBYTE = 0x5,
@@ -235,7 +235,7 @@ inline var_types JitType2PreciseVarType(CorInfoType type)
235235
// see the definition of enum CorInfoType in file inc/corinfo.h
236236
TYP_UNDEF, // CORINFO_TYPE_UNDEF = 0x0,
237237
TYP_VOID, // CORINFO_TYPE_VOID = 0x1,
238-
TYP_BOOL, // CORINFO_TYPE_BOOL = 0x2,
238+
TYP_UBYTE, // CORINFO_TYPE_BOOL = 0x2,
239239
TYP_USHORT, // CORINFO_TYPE_CHAR = 0x3,
240240
TYP_BYTE, // CORINFO_TYPE_BYTE = 0x4,
241241
TYP_UBYTE, // CORINFO_TYPE_UBYTE = 0x5,

‎src/coreclr/jit/gentree.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -7696,7 +7696,6 @@ GenTree* Compiler::gtNewGenericCon(var_types type, uint8_t* cnsVal)
76967696
READ_VALUE(int8_t);
76977697
return gtNewIconNode(val);
76987698
}
7699-
case TYP_BOOL:
77007699
case TYP_UBYTE:
77017700
{
77027701
READ_VALUE(uint8_t);
@@ -7790,7 +7789,6 @@ GenTree* Compiler::gtNewConWithPattern(var_types type, uint8_t pattern)
77907789
{
77917790
switch (type)
77927791
{
7793-
case TYP_BOOL:
77947792
case TYP_UBYTE:
77957793
return gtNewIconNode(pattern);
77967794
case TYP_BYTE:
@@ -14279,7 +14277,7 @@ GenTree* Compiler::gtFoldBoxNullable(GenTree* tree)
1427914277

1428014278
static_assert_no_msg(OFFSETOF__CORINFO_NullableOfT__hasValue == 0);
1428114279
GenTree* srcAddr = call->gtArgs.GetArgByIndex(1)->GetNode();
14282-
GenTree* hasValueNode = gtNewIndir(TYP_BOOL, srcAddr);
14280+
GenTree* hasValueNode = gtNewIndir(TYP_UBYTE, srcAddr);
1428314281

1428414282
if (op == op1)
1428514283
{
@@ -14849,7 +14847,6 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
1484914847
i1 = INT32(UINT16(i1));
1485014848
goto CNS_INT;
1485114849

14852-
case TYP_BOOL:
1485314850
case TYP_UBYTE:
1485414851
i1 = INT32(UINT8(i1));
1485514852
goto CNS_INT;
@@ -21333,7 +21330,7 @@ GenTree* Compiler::gtNewSimdCmpOpAllNode(
2133321330
genTreeOps op, var_types type, GenTree* op1, GenTree* op2, CorInfoType simdBaseJitType, unsigned simdSize)
2133421331
{
2133521332
assert(IsBaselineSimdIsaSupportedDebugOnly());
21336-
assert(type == TYP_BOOL);
21333+
assert(type == TYP_UBYTE);
2133721334

2133821335
var_types simdType = getSIMDTypeForSize(simdSize);
2133921336
assert(varTypeIsSIMD(simdType));
@@ -21472,7 +21469,7 @@ GenTree* Compiler::gtNewSimdCmpOpAnyNode(
2147221469
genTreeOps op, var_types type, GenTree* op1, GenTree* op2, CorInfoType simdBaseJitType, unsigned simdSize)
2147321470
{
2147421471
assert(IsBaselineSimdIsaSupportedDebugOnly());
21475-
assert(type == TYP_BOOL);
21472+
assert(type == TYP_UBYTE);
2147621473

2147721474
var_types simdType = getSIMDTypeForSize(simdSize);
2147821475
assert(varTypeIsSIMD(simdType));

‎src/coreclr/jit/importer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,9 @@ bool Compiler::impCheckImplicitArgumentCoercion(var_types sigType, var_types nod
685685
return true;
686686
}
687687

688-
if (TypeIs(sigType, TYP_BOOL, TYP_UBYTE, TYP_BYTE, TYP_USHORT, TYP_SHORT, TYP_UINT, TYP_INT))
688+
if (TypeIs(sigType, TYP_UBYTE, TYP_BYTE, TYP_USHORT, TYP_SHORT, TYP_UINT, TYP_INT))
689689
{
690-
if (TypeIs(nodeType, TYP_BOOL, TYP_UBYTE, TYP_BYTE, TYP_USHORT, TYP_SHORT, TYP_UINT, TYP_INT, TYP_I_IMPL))
690+
if (TypeIs(nodeType, TYP_UBYTE, TYP_BYTE, TYP_USHORT, TYP_SHORT, TYP_UINT, TYP_INT, TYP_I_IMPL))
691691
{
692692
return true;
693693
}
@@ -2990,7 +2990,7 @@ int Compiler::impBoxPatternMatch(CORINFO_RESOLVED_TOKEN* pResolvedToken,
29902990
objToBox = impGetNodeAddr(objToBox, CHECK_SPILL_ALL, &indirFlags);
29912991

29922992
static_assert_no_msg(OFFSETOF__CORINFO_NullableOfT__hasValue == 0);
2993-
impPushOnStack(gtNewIndir(TYP_BOOL, objToBox), typeInfo(TYP_INT));
2993+
impPushOnStack(gtNewIndir(TYP_UBYTE, objToBox), typeInfo(TYP_INT));
29942994

29952995
JITDUMP("\n Importing BOX; ISINST; BR_TRUE/FALSE as nullableVT.hasValue\n");
29962996
return 1 + sizeof(mdToken);

‎src/coreclr/jit/importervectorization.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ GenTree* Compiler::impExpandHalfConstEqualsSIMD(
200200
// Optimization: use a single load when byteLen equals simdSize.
201201
// For code simplicity we always create nodes for two vectors case.
202202
const bool useSingleVector = simdSize == byteLen;
203-
return gtNewSimdCmpOpAllNode(GT_EQ, TYP_BOOL, useSingleVector ? xor1 : orr, gtNewZeroConNode(simdType), baseType,
203+
return gtNewSimdCmpOpAllNode(GT_EQ, TYP_UBYTE, useSingleVector ? xor1 : orr, gtNewZeroConNode(simdType), baseType,
204204
simdSize);
205205

206206
// Codegen example for byteLen=40 and OrdinalIgnoreCase mode with AVX:
@@ -486,7 +486,7 @@ GenTree* Compiler::impExpandHalfConstEquals(GenTreeLclVarCommon* data,
486486
JITDUMP("unable to compose indirCmp\n");
487487
return nullptr;
488488
}
489-
assert(indirCmp->TypeIs(TYP_INT, TYP_BOOL));
489+
assert(indirCmp->TypeIs(TYP_INT, TYP_UBYTE));
490490

491491
GenTreeColon* lenCheckColon = gtNewColonNode(TYP_INT, indirCmp, gtNewFalse());
492492

‎src/coreclr/jit/lclmorph.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -1144,13 +1144,6 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
11441144
return IndirTransform::LclVar;
11451145
}
11461146

1147-
// Bool and ubyte are the same type.
1148-
if ((indir->TypeIs(TYP_BOOL) && (varDsc->TypeGet() == TYP_UBYTE)) ||
1149-
(indir->TypeIs(TYP_UBYTE) && (varDsc->TypeGet() == TYP_BOOL)))
1150-
{
1151-
return IndirTransform::LclVar;
1152-
}
1153-
11541147
// For small stores we can ignore the signed/unsigned diff.
11551148
if (isDef && (varTypeToSigned(indir) == varTypeToSigned(varDsc)))
11561149
{

‎src/coreclr/jit/lclvars.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,6 @@ void Compiler::lvaInitVarDsc(LclVarDsc* varDsc,
15011501
varDsc->lvType = type;
15021502
}
15031503

1504-
if (type == TYP_BOOL)
1505-
{
1506-
varDsc->lvIsBoolean = true;
1507-
}
1508-
15091504
#ifdef DEBUG
15101505
varDsc->SetStackOffset(BAD_STK_OFFS);
15111506
#endif
@@ -4078,7 +4073,6 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt,
40784073
{
40794074
if (varDsc->IsAddressExposed())
40804075
{
4081-
varDsc->lvIsBoolean = false;
40824076
varDsc->lvAllDefsAreNoGc = false;
40834077
}
40844078

@@ -4101,34 +4095,6 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt,
41014095
varDsc->lvAllDefsAreNoGc = false;
41024096
}
41034097

4104-
if (value->gtType != TYP_BOOL)
4105-
{
4106-
// Is the value clearly a boolean one?
4107-
switch (value->gtOper)
4108-
{
4109-
case GT_CNS_INT:
4110-
if (value->AsIntCon()->gtIconVal == 0)
4111-
{
4112-
break;
4113-
}
4114-
if (value->AsIntCon()->gtIconVal == 1)
4115-
{
4116-
break;
4117-
}
4118-
4119-
// Not 0 or 1, fall through ....
4120-
FALLTHROUGH;
4121-
default:
4122-
if (value->OperIsCompare())
4123-
{
4124-
break;
4125-
}
4126-
4127-
varDsc->lvIsBoolean = false;
4128-
break;
4129-
}
4130-
}
4131-
41324098
if (!varDsc->lvDisqualifySingleDefRegCandidate) // If this var is already disqualified, we can skip this
41334099
{
41344100
bool bbInALoop = (block->bbFlags & BBF_BACKWARD_JUMP) != 0;

‎src/coreclr/jit/lower.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ GenTree* Lowering::LowerCallMemcmp(GenTreeCall* call)
19671967
if (GenTree::OperIsCmpCompare(oper))
19681968
{
19691969
assert(type == TYP_INT);
1970-
return comp->gtNewSimdCmpOpAllNode(oper, TYP_BOOL, op1, op2, CORINFO_TYPE_NATIVEUINT,
1970+
return comp->gtNewSimdCmpOpAllNode(oper, TYP_UBYTE, op1, op2, CORINFO_TYPE_NATIVEUINT,
19711971
genTypeSize(op1));
19721972
}
19731973
return comp->gtNewSimdBinOpNode(oper, op1->TypeGet(), op1, op2, CORINFO_TYPE_NATIVEUINT,
@@ -3441,7 +3441,7 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
34413441
var_types castToType = cast->CastToType();
34423442
GenTree* castOp = cast->gtGetOp1();
34433443

3444-
if (((castToType == TYP_BOOL) || (castToType == TYP_UBYTE)) && FitsIn<UINT8>(op2Value))
3444+
if ((castToType == TYP_UBYTE) && FitsIn<UINT8>(op2Value))
34453445
{
34463446
//
34473447
// Since we're going to remove the cast we need to be able to narrow the cast operand

‎src/coreclr/jit/lowerarmarch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ GenTree* Lowering::LowerHWIntrinsicCmpOp(GenTreeHWIntrinsic* node, genTreeOps cm
12611261
assert(varTypeIsSIMD(simdType));
12621262
assert(varTypeIsArithmetic(simdBaseType));
12631263
assert(simdSize != 0);
1264-
assert(node->gtType == TYP_BOOL);
1264+
assert(node->gtType == TYP_UBYTE);
12651265
assert((cmpOp == GT_EQ) || (cmpOp == GT_NE));
12661266

12671267
// We have the following (with the appropriate simd size and where the intrinsic could be op_Inequality):

‎src/coreclr/jit/lowerxarch.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ GenTree* Lowering::LowerHWIntrinsicCmpOp(GenTreeHWIntrinsic* node, genTreeOps cm
16921692
assert(varTypeIsSIMD(simdType));
16931693
assert(varTypeIsArithmetic(simdBaseType));
16941694
assert(simdSize != 0);
1695-
assert(node->gtType == TYP_BOOL);
1695+
assert(node->gtType == TYP_UBYTE);
16961696
assert((cmpOp == GT_EQ) || (cmpOp == GT_NE));
16971697

16981698
// We have the following (with the appropriate simd size and where the intrinsic could be op_Inequality):

‎src/coreclr/jit/optimizebools.cpp

+1-14
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,7 @@ GenTree* OptBoolsDsc::optIsBoolComp(OptTestInfo* pOptTest)
12821282
ssize_t ival2 = opr2->AsIntCon()->gtIconVal;
12831283

12841284
// Is the value a boolean?
1285-
// We can either have a boolean expression (marked GTF_BOOLEAN) or
1286-
// a local variable that is marked as being boolean (lvIsBoolean)
1285+
// We can either have a boolean expression (marked GTF_BOOLEAN) or a constant 0/1.
12871286

12881287
if (opr1->gtFlags & GTF_BOOLEAN)
12891288
{
@@ -1293,18 +1292,6 @@ GenTree* OptBoolsDsc::optIsBoolComp(OptTestInfo* pOptTest)
12931292
{
12941293
pOptTest->isBool = true;
12951294
}
1296-
else if (opr1->gtOper == GT_LCL_VAR)
1297-
{
1298-
// is it a boolean local variable?
1299-
1300-
unsigned lclNum = opr1->AsLclVarCommon()->GetLclNum();
1301-
noway_assert(lclNum < m_comp->lvaCount);
1302-
1303-
if (m_comp->lvaTable[lclNum].lvIsBoolean)
1304-
{
1305-
pOptTest->isBool = true;
1306-
}
1307-
}
13081295

13091296
// Was our comparison against the constant 1 (i.e. true)
13101297
if (ival2 == 1)

‎src/coreclr/jit/optimizer.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -5734,7 +5734,6 @@ bool Compiler::optNarrowTree(GenTree* tree, var_types srct, var_types dstt, Valu
57345734
case TYP_BYTE:
57355735
lmask = 0x0000007F;
57365736
break;
5737-
case TYP_BOOL:
57385737
case TYP_UBYTE:
57395738
lmask = 0x000000FF;
57405739
break;
@@ -5782,7 +5781,6 @@ bool Compiler::optNarrowTree(GenTree* tree, var_types srct, var_types dstt, Valu
57825781
case TYP_BYTE:
57835782
imask = 0x0000007F;
57845783
break;
5785-
case TYP_BOOL:
57865784
case TYP_UBYTE:
57875785
imask = 0x000000FF;
57885786
break;

‎src/coreclr/jit/rangecheck.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ Range RangeCheck::GetRangeFromType(var_types type)
11101110
{
11111111
switch (type)
11121112
{
1113-
case TYP_BOOL:
11141113
case TYP_UBYTE:
11151114
return Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, BYTE_MAX));
11161115
case TYP_BYTE:

‎src/coreclr/jit/typelist.h

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ tf )
3737
DEF_TP(UNDEF ,"<UNDEF>" , TYP_UNDEF, 0, 0, 0, 0, 0, VTR_INT, availableIntRegs, RBM_INT_CALLEE_SAVED, RBM_INT_CALLEE_TRASH, VTF_ANY)
3838
DEF_TP(VOID ,"void" , TYP_VOID, 0, 0, 0, 0, 0, VTR_INT, availableIntRegs, RBM_INT_CALLEE_SAVED, RBM_INT_CALLEE_TRASH, VTF_ANY)
3939

40-
DEF_TP(BOOL ,"bool" , TYP_INT, 1, 1, 4, 1, 1, VTR_INT, availableIntRegs, RBM_INT_CALLEE_SAVED, RBM_INT_CALLEE_TRASH, VTF_INT|VTF_UNS)
4140
DEF_TP(BYTE ,"byte" , TYP_INT, 1, 1, 4, 1, 1, VTR_INT, availableIntRegs, RBM_INT_CALLEE_SAVED, RBM_INT_CALLEE_TRASH, VTF_INT)
4241
DEF_TP(UBYTE ,"ubyte" , TYP_INT, 1, 1, 4, 1, 1, VTR_INT, availableIntRegs, RBM_INT_CALLEE_SAVED, RBM_INT_CALLEE_TRASH, VTF_INT|VTF_UNS)
4342

‎src/coreclr/jit/utils.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -3855,7 +3855,6 @@ bool CastFromIntOverflows(int32_t fromValue, var_types toType, bool fromUnsigned
38553855
{
38563856
switch (toType)
38573857
{
3858-
case TYP_BOOL:
38593858
case TYP_BYTE:
38603859
case TYP_UBYTE:
38613860
case TYP_SHORT:
@@ -3879,7 +3878,6 @@ bool CastFromLongOverflows(int64_t fromValue, var_types toType, bool fromUnsigne
38793878
{
38803879
switch (toType)
38813880
{
3882-
case TYP_BOOL:
38833881
case TYP_BYTE:
38843882
case TYP_UBYTE:
38853883
case TYP_SHORT:
@@ -3994,7 +3992,6 @@ bool CastFromFloatOverflows(float fromValue, var_types toType)
39943992
{
39953993
case TYP_BYTE:
39963994
return !(-129.0f < fromValue && fromValue < 128.0f);
3997-
case TYP_BOOL:
39983995
case TYP_UBYTE:
39993996
return !(-1.0f < fromValue && fromValue < 256.0f);
40003997
case TYP_SHORT:
@@ -4023,7 +4020,6 @@ bool CastFromDoubleOverflows(double fromValue, var_types toType)
40234020
{
40244021
case TYP_BYTE:
40254022
return !(-129.0 < fromValue && fromValue < 128.0);
4026-
case TYP_BOOL:
40274023
case TYP_UBYTE:
40284024
return !(-1.0 < fromValue && fromValue < 256.0);
40294025
case TYP_SHORT:

‎src/coreclr/jit/utils.h

-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,6 @@ bool FitsIn(var_types type, T value)
10021002
{
10031003
case TYP_BYTE:
10041004
return FitsIn<int8_t>(value);
1005-
case TYP_BOOL:
10061005
case TYP_UBYTE:
10071006
return FitsIn<uint8_t>(value);
10081007
case TYP_SHORT:

0 commit comments

Comments
 (0)
Please sign in to comment.