Skip to content

Commit 2fe8937

Browse files
authored
JIT: Optimize ConditionalSelect with const zero when condition is not TYP_MASK (#113864)
* optimize ConditionalSelect with const zero * remove superfluous LowerNode calls * Revert "remove superfluous LowerNode calls" This reverts commit 6dae598. * just remove one LowerNode call * Revert "just remove one LowerNode call" This reverts commit 17886e7.
1 parent e1cd060 commit 2fe8937

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/coreclr/jit/lowerxarch.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,37 @@ GenTree* Lowering::LowerHWIntrinsicCndSel(GenTreeHWIntrinsic* node)
34703470
blendVariableId = NI_EVEX_BlendVariableMask;
34713471
op1 = maskNode;
34723472
}
3473+
else if (op2->IsVectorZero() || op3->IsVectorZero())
3474+
{
3475+
// If either of the value operands is const zero, we can optimize down to AND or AND_NOT.
3476+
GenTree* binOp = nullptr;
3477+
3478+
if (op3->IsVectorZero())
3479+
{
3480+
binOp = comp->gtNewSimdBinOpNode(GT_AND, simdType, op1, op2, simdBaseJitType, simdSize);
3481+
BlockRange().Remove(op3);
3482+
}
3483+
else
3484+
{
3485+
binOp = comp->gtNewSimdBinOpNode(GT_AND_NOT, simdType, op3, op1, simdBaseJitType, simdSize);
3486+
BlockRange().Remove(op2);
3487+
}
3488+
3489+
BlockRange().InsertAfter(node, binOp);
3490+
3491+
LIR::Use use;
3492+
if (BlockRange().TryGetUse(node, &use))
3493+
{
3494+
use.ReplaceWith(binOp);
3495+
}
3496+
else
3497+
{
3498+
binOp->SetUnusedValue();
3499+
}
3500+
3501+
BlockRange().Remove(node);
3502+
return LowerNode(binOp);
3503+
}
34733504
else if (simdSize == 32)
34743505
{
34753506
// For Vector256 (simdSize == 32), BlendVariable for floats/doubles

0 commit comments

Comments
 (0)