@@ -5438,7 +5438,8 @@ GlobOpt::GetPrepassValueTypeForDst(
54385438 IR::Instr *const instr,
54395439 Value *const src1Value,
54405440 Value *const src2Value,
5441- bool const isValueInfoPrecise) const
5441+ bool const isValueInfoPrecise,
5442+ bool const isSafeToTransferInPrepass) const
54425443{
54435444 // Values with definite types can be created in the loop prepass only when it is guaranteed that the value type will be the
54445445 // same on any iteration of the loop. The heuristics currently used are:
@@ -5455,13 +5456,13 @@ GlobOpt::GetPrepassValueTypeForDst(
54555456 Assert(IsLoopPrePass());
54565457 Assert(instr);
54575458
5458- if(!desiredValueType.IsDefinite())
5459- {
5460- return desiredValueType;
5461- }
5462-
54635459 if(!isValueInfoPrecise)
54645460 {
5461+ if(!desiredValueType.IsDefinite())
5462+ {
5463+ return isSafeToTransferInPrepass ? desiredValueType : desiredValueType.SetCanBeTaggedValue(true);
5464+ }
5465+
54655466 // If the desired value type is not precise, the value type of the destination is derived from the value types of the
54665467 // sources. Since the value type of a source sym is not definite, the destination value type also cannot be definite.
54675468 if(desiredValueType.IsInt() && OpCodeAttr::IsInt32(instr->m_opcode))
@@ -5474,6 +5475,7 @@ GlobOpt::GetPrepassValueTypeForDst(
54745475 // The op always produces a number, but not always an int
54755476 return desiredValueType.ToDefiniteAnyNumber();
54765477 }
5478+ // Note: ToLikely() also sets CanBeTaggedValue
54775479 return desiredValueType.ToLikely();
54785480 }
54795481
@@ -5750,7 +5752,7 @@ GlobOpt::ValueNumberTransferDstInPrepass(IR::Instr *const instr, Value *const sr
57505752 bool isSafeToTransferInPrepass = false;
57515753 isValueInfoPrecise = IsPrepassSrcValueInfoPrecise(instr, src1Val, nullptr, &isSafeToTransferInPrepass);
57525754
5753- const ValueType valueType(GetPrepassValueTypeForDst(src1ValueInfo->Type(), instr, src1Val, nullptr, isValueInfoPrecise));
5755+ const ValueType valueType(GetPrepassValueTypeForDst(src1ValueInfo->Type(), instr, src1Val, nullptr, isValueInfoPrecise, isSafeToTransferInPrepass ));
57545756 if(isValueInfoPrecise || isSafeToTransferInPrepass)
57555757 {
57565758 Assert(valueType == src1ValueInfo->Type());
0 commit comments