Skip to content

Commit

Permalink
JIT: avoid folding operations with relocatable immediates (dotnet/cor…
Browse files Browse the repository at this point in the history
…eclr#21511)

In general, don't fold operations on relocatable immediates. Only allow EQ/NE folding, since relocation should preserve identity but not bit values or relative comparisons.

Closes dotnet/coreclr#21483.

Commit migrated from dotnet/coreclr@6b9e1dc
  • Loading branch information
AndyAyersMS committed Dec 13, 2018
1 parent 99879b6 commit cdd65fb
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/coreclr/src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12995,7 +12995,12 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
case TYP_INT:

/* Fold constant INT unary operator */
assert(op1->gtIntCon.ImmedValCanBeFolded(this, tree->OperGet()));

if (!op1->gtIntCon.ImmedValCanBeFolded(this, tree->OperGet()))
{
return tree;
}

i1 = (int)op1->gtIntCon.gtIconVal;

// If we fold a unary oper, then the folded constant
Expand Down Expand Up @@ -13148,7 +13153,11 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)

/* Fold constant LONG unary operator */

assert(op1->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()));
if (!op1->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()))
{
return tree;
}

lval1 = op1->gtIntConCommon.LngValue();

switch (tree->gtOper)
Expand Down Expand Up @@ -13489,8 +13498,15 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
//
assert(!varTypeIsGC(op1->gtType) && !varTypeIsGC(op2->gtType));

assert(op1->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()));
assert(op2->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()));
if (!op1->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()))
{
return tree;
}

if (!op2->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()))
{
return tree;
}

i1 = op1->gtIntConCommon.IconValue();
i2 = op2->gtIntConCommon.IconValue();
Expand Down Expand Up @@ -13851,8 +13867,15 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
//
assert((op2->gtType == TYP_LONG) || (op2->gtType == TYP_INT));

assert(op1->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()));
assert(op2->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()));
if (!op1->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()))
{
return tree;
}

if (!op2->gtIntConCommon.ImmedValCanBeFolded(this, tree->OperGet()))
{
return tree;
}

lval1 = op1->gtIntConCommon.LngValue();

Expand Down

0 comments on commit cdd65fb

Please sign in to comment.