Skip to content

Commit

Permalink
Fix invalid lowering for SELECT over mixed neg/not operands (#87674)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwapnilGaikwad authored Jun 16, 2023
1 parent 783402c commit d334f0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ void Lowering::TryLowerCselToCinvOrCneg(GenTreeOp* select, GenTree* cond)

assert(trueVal->OperIs(GT_NOT, GT_NEG) || falseVal->OperIs(GT_NOT, GT_NEG));

if (trueVal->OperIs(GT_NOT) || trueVal->OperIs(GT_NEG))
if ((isCneg && trueVal->OperIs(GT_NEG)) || (!isCneg && trueVal->OperIs(GT_NOT)))
{
shouldReverseCondition = true;
invertedOrNegatedVal = trueVal->gtGetOp1();
Expand Down
19 changes: 19 additions & 0 deletions src/tests/JIT/opt/Compares/conditionalNegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,23 @@ public static void cneg_shifted_true_oper(int op1, int op2, int expected)
int result = op1 < 51 ? -(op1 >> 3) : op2;
Assert.Equal(expected, result);
}

[Theory]
[InlineData(1, -1)]
[InlineData(55, ~55)]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void cneg_mixed_not_and_neg_oper(int op1, int expected)
{
//ARM64-FULL-LINE: cmp {{w[0-9]+}}, #52
//ARM64-FULL-LINE-NEXT: csneg {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, {{gt|le}}
if (op1 <= 52)
{
op1 = -op1;
}
else
{
op1 = ~op1;
}
Assert.Equal(expected, op1);
}
}

0 comments on commit d334f0c

Please sign in to comment.