Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}