From 01735f33e8c584b20f9d605007389f13f0b0687d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 13 Oct 2024 19:42:29 +0200 Subject: [PATCH 1/2] Remove redundant sign/zero extension for SIMD broadcasts --- src/coreclr/jit/lowerxarch.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 1da40d1dc453b..1a20e57a7c66e 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -10356,6 +10356,22 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) op1 = node->Op(1); op1->ClearContained(); + + // Drop GT_CAST if it doesn't change the op1's bits we're about to broadcast + if (op1->OperIs(GT_CAST) && !op1->gtOverflow()) + { + GenTreeCast* cast = op1->AsCast(); + if (!varTypeIsFloating(cast->CastToType()) && + !varTypeIsFloating(cast->CastFromType()) && + (genTypeSize(cast->CastToType()) >= genTypeSize(simdBaseType)) && + (genTypeSize(cast->CastFromType()) >= genTypeSize(simdBaseType))) + { + BlockRange().Remove(op1); + op1 = cast->CastOp(); + op1->ClearContained(); + node->Op(1) = op1; + } + } } } break; From be5d178c0a60b5869ba886a4470ba4fd1e42896d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 13 Oct 2024 20:58:52 +0200 Subject: [PATCH 2/2] don't do it for minopts --- src/coreclr/jit/lowerxarch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 1a20e57a7c66e..51b984e75303d 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -10358,7 +10358,7 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) op1->ClearContained(); // Drop GT_CAST if it doesn't change the op1's bits we're about to broadcast - if (op1->OperIs(GT_CAST) && !op1->gtOverflow()) + if (op1->OperIs(GT_CAST) && !op1->gtOverflow() && comp->opts.Tier0OptimizationEnabled()) { GenTreeCast* cast = op1->AsCast(); if (!varTypeIsFloating(cast->CastToType()) &&