diff options
author | Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com> | 2018-06-26 16:57:47 +0200 |
---|---|---|
committer | Andy Ayers <andya@microsoft.com> | 2018-06-26 07:57:47 -0700 |
commit | 4e237f058b12403f7ee69d62fd24053081d5fe13 (patch) | |
tree | 1a44fcfe4ec6ad32bb4c5ba7b5da1f7db704bfc1 /src/jit/valuenum.cpp | |
parent | c17e34f4120f551c70be88fef835abc7640a2e00 (diff) | |
download | coreclr-4e237f058b12403f7ee69d62fd24053081d5fe13.tar.gz coreclr-4e237f058b12403f7ee69d62fd24053081d5fe13.tar.bz2 coreclr-4e237f058b12403f7ee69d62fd24053081d5fe13.zip |
Fix value numbering when selecting a constant (#18627)
When applying selectors, constants were special-cased to not require any
type casts. However this is wrong if a narrowing needs to be performed.
Fix #18235
Diffstat (limited to 'src/jit/valuenum.cpp')
-rw-r--r-- | src/jit/valuenum.cpp | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/src/jit/valuenum.cpp b/src/jit/valuenum.cpp index 6bf8429abe..38ef43f64c 100644 --- a/src/jit/valuenum.cpp +++ b/src/jit/valuenum.cpp @@ -2568,49 +2568,41 @@ ValueNum ValueNumStore::VNApplySelectorsTypeCheck(ValueNum elem, var_types indTy if (indType != elemTyp) { - bool isConstant = IsVNConstant(elem); - if (isConstant && (elemTyp == genActualType(indType))) + // We are trying to read from an 'elem' of type 'elemType' using 'indType' read + + size_t elemTypSize = (elemTyp == TYP_STRUCT) ? elemStructSize : genTypeSize(elemTyp); + size_t indTypeSize = genTypeSize(indType); + + if ((indType == TYP_REF) && (varTypeIsStruct(elemTyp))) { - // (i.e. We recorded a constant of TYP_INT for a TYP_BYTE field) + // indType is TYP_REF and elemTyp is TYP_STRUCT + // + // We have a pointer to a static that is a Boxed Struct + // + return elem; } - else + else if (indTypeSize > elemTypSize) { - // We are trying to read from an 'elem' of type 'elemType' using 'indType' read - - size_t elemTypSize = (elemTyp == TYP_STRUCT) ? elemStructSize : genTypeSize(elemTyp); - size_t indTypeSize = genTypeSize(indType); - - if ((indType == TYP_REF) && (varTypeIsStruct(elemTyp))) - { - // indType is TYP_REF and elemTyp is TYP_STRUCT - // - // We have a pointer to a static that is a Boxed Struct - // - return elem; - } - else if (indTypeSize > elemTypSize) - { - // Reading beyong the end of 'elem' + // Reading beyong the end of 'elem' - // return a new unique value number - elem = VNForExpr(nullptr, indType); - JITDUMP(" *** Mismatched types in VNApplySelectorsTypeCheck (reading beyond the end)\n"); - } - else if (varTypeIsStruct(indType)) - { - // indType is TYP_STRUCT + // return a new unique value number + elem = VNForExpr(nullptr, indType); + JITDUMP(" *** Mismatched types in VNApplySelectorsTypeCheck (reading beyond the end)\n"); + } + else if (varTypeIsStruct(indType)) + { + // indType is TYP_STRUCT - // return a new unique value number - elem = VNForExpr(nullptr, indType); - JITDUMP(" *** Mismatched types in VNApplySelectorsTypeCheck (indType is TYP_STRUCT)\n"); - } - else - { - // We are trying to read an 'elem' of type 'elemType' using 'indType' read + // return a new unique value number + elem = VNForExpr(nullptr, indType); + JITDUMP(" *** Mismatched types in VNApplySelectorsTypeCheck (indType is TYP_STRUCT)\n"); + } + else + { + // We are trying to read an 'elem' of type 'elemType' using 'indType' read - // insert a cast of elem to 'indType' - elem = VNForCast(elem, indType, elemTyp); - } + // insert a cast of elem to 'indType' + elem = VNForCast(elem, indType, elemTyp); } } return elem; |