diff options
author | Sivarv <sivarv@microsoft.com> | 2017-03-06 10:25:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-06 10:25:03 -0800 |
commit | 65dcffc4376ebff8c905ccfc9fa9a4ad0aca818c (patch) | |
tree | 92949ed14b3863b8111ae076876ea28aabea20d0 | |
parent | 61619268805bace6b730de1237fd3c7545eb99b5 (diff) | |
parent | 89b2d06f865333bacf2aef4166d2c9fd22632e36 (diff) | |
download | coreclr-65dcffc4376ebff8c905ccfc9fa9a4ad0aca818c.tar.gz coreclr-65dcffc4376ebff8c905ccfc9fa9a4ad0aca818c.tar.bz2 coreclr-65dcffc4376ebff8c905ccfc9fa9a4ad0aca818c.zip |
Merge pull request #9398 from mikedn/switch-cast
Change switch value widening
-rw-r--r-- | src/jit/importer.cpp | 20 | ||||
-rw-r--r-- | src/jit/lower.cpp | 14 |
2 files changed, 12 insertions, 22 deletions
diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index b21fc12438..ef70d059ff 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -11575,22 +11575,6 @@ void Compiler::impImportBlockCode(BasicBlock* block) op1 = impPopStack().val; assertImp(genActualTypeIsIntOrI(op1->TypeGet())); -#ifdef _TARGET_64BIT_ - // Widen 'op1' on 64-bit targets - if (op1->TypeGet() != TYP_I_IMPL) - { - if (op1->OperGet() == GT_CNS_INT) - { - op1->gtType = TYP_I_IMPL; - } - else - { - op1 = gtNewCastNode(TYP_I_IMPL, op1, TYP_I_IMPL); - } - } -#endif // _TARGET_64BIT_ - assert(genActualType(op1->TypeGet()) == TYP_I_IMPL); - /* We can create a switch node */ op1 = gtNewOperNode(GT_SWITCH, TYP_VOID, op1); @@ -15976,11 +15960,11 @@ SPILLSTACK: } else { - assert(addTree->gtOper == GT_SWITCH && genActualType(addTree->gtOp.gtOp1->gtType) == TYP_I_IMPL); + assert(addTree->gtOper == GT_SWITCH && genActualTypeIsIntOrI(addTree->gtOp.gtOp1->TypeGet())); unsigned temp = lvaGrabTemp(true DEBUGARG("spill addStmt SWITCH")); impAssignTempGen(temp, addTree->gtOp.gtOp1, level); - addTree->gtOp.gtOp1 = gtNewLclvNode(temp, TYP_I_IMPL); + addTree->gtOp.gtOp1 = gtNewLclvNode(temp, genActualType(addTree->gtOp.gtOp1->TypeGet())); } } diff --git a/src/jit/lower.cpp b/src/jit/lower.cpp index 2a65a949fd..9242c395a3 100644 --- a/src/jit/lower.cpp +++ b/src/jit/lower.cpp @@ -468,7 +468,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node) // both GT_SWITCH lowering code paths. // This condition is of the form: if (temp > jumpTableLength - 2){ goto jumpTable[jumpTableLength - 1]; } GenTreePtr gtDefaultCaseCond = comp->gtNewOperNode(GT_GT, TYP_INT, comp->gtNewLclvNode(tempLclNum, tempLclType), - comp->gtNewIconNode(jumpCnt - 2, TYP_INT)); + comp->gtNewIconNode(jumpCnt - 2, tempLclType)); // Make sure we perform an unsigned comparison, just in case the switch index in 'temp' // is now less than zero 0 (that would also hit the default case). @@ -681,9 +681,16 @@ GenTree* Lowering::LowerSwitch(GenTree* node) JITDUMP("Lowering switch BB%02u: using jump table expansion\n", originalSwitchBB->bbNum); + GenTree* switchValue = comp->gtNewLclvNode(tempLclNum, tempLclType); +#ifdef _TARGET_64BIT_ + if (tempLclType != TYP_I_IMPL) + { + // Note that the switch value is unsigned so the cast should be unsigned as well. + switchValue = comp->gtNewCastNode(TYP_I_IMPL, switchValue, TYP_U_IMPL); + } +#endif GenTreePtr gtTableSwitch = - comp->gtNewOperNode(GT_SWITCH_TABLE, TYP_VOID, comp->gtNewLclvNode(tempLclNum, tempLclType), - comp->gtNewJmpTableNode()); + comp->gtNewOperNode(GT_SWITCH_TABLE, TYP_VOID, switchValue, comp->gtNewJmpTableNode()); /* Increment the lvRefCnt and lvRefCntWtd for temp */ tempVarDsc->incRefCnts(blockWeight, comp); @@ -2257,7 +2264,6 @@ void Lowering::LowerCompare(GenTree* cmp) // automatically inserts a cast from int32 to long on 64 bit architectures. However, the JIT // accidentally generates int/long comparisons internally: // - loop cloning compares int (and even small int) index limits against long constants - // - switch lowering compares a 64 bit switch value against a int32 constant // // TODO-Cleanup: The above mentioned issues should be fixed and then the code below may be // replaced with an assert or at least simplified. The special casing of constants in code |