From 5a1ebd2638b58067c0fe9dbe7d4ff1dec3ad3a62 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Mon, 25 Nov 2024 09:31:38 +0100 Subject: [PATCH] Remove redundant sign/zero extension for SIMD broadcasts (#108824) --- 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 41ae0a9fc6d3b..87528fee51bdf 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -10377,6 +10377,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() && comp->opts.Tier0OptimizationEnabled()) + { + 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;