Skip to content

Commit d334f0c

Browse files
Fix invalid lowering for SELECT over mixed neg/not operands (#87674)
1 parent 783402c commit d334f0c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/coreclr/jit/lowerarmarch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ void Lowering::TryLowerCselToCinvOrCneg(GenTreeOp* select, GenTree* cond)
25792579

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

2582-
if (trueVal->OperIs(GT_NOT) || trueVal->OperIs(GT_NEG))
2582+
if ((isCneg && trueVal->OperIs(GT_NEG)) || (!isCneg && trueVal->OperIs(GT_NOT)))
25832583
{
25842584
shouldReverseCondition = true;
25852585
invertedOrNegatedVal = trueVal->gtGetOp1();

src/tests/JIT/opt/Compares/conditionalNegates.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,23 @@ public static void cneg_shifted_true_oper(int op1, int op2, int expected)
129129
int result = op1 < 51 ? -(op1 >> 3) : op2;
130130
Assert.Equal(expected, result);
131131
}
132+
133+
[Theory]
134+
[InlineData(1, -1)]
135+
[InlineData(55, ~55)]
136+
[MethodImpl(MethodImplOptions.NoInlining)]
137+
public static void cneg_mixed_not_and_neg_oper(int op1, int expected)
138+
{
139+
//ARM64-FULL-LINE: cmp {{w[0-9]+}}, #52
140+
//ARM64-FULL-LINE-NEXT: csneg {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, {{gt|le}}
141+
if (op1 <= 52)
142+
{
143+
op1 = -op1;
144+
}
145+
else
146+
{
147+
op1 = ~op1;
148+
}
149+
Assert.Equal(expected, op1);
150+
}
132151
}

0 commit comments

Comments
 (0)