@@ -337,24 +337,25 @@ static FailureOr<Value> implementAssignLayoutStep(
337337 }
338338
339339 // The result can be simplified if the layout is dense in the ciphertext type,
340- // and if the input is a scalar or a constant splat.
341- if (isDenseLayout (rel, targetType)) {
340+ // and the input is a scalar or a constant splat.
341+ SplatElementsAttr splatAttr;
342+ bool inputIsScalar = !dataSemanticType;
343+ bool inputIsSplatConstant = matchPattern (input, m_Constant (&splatAttr));
344+ if ((inputIsScalar || inputIsSplatConstant) &&
345+ isDenseLayout (rel, targetType)) {
342346 // Regardless of being constant or not, a scalar can be splat into the
343347 // ciphertext tensor.
344- if (!dataSemanticType ) {
348+ if (inputIsScalar ) {
345349 auto splatOp = tensor::SplatOp::create (builder, targetType, input);
346350 createdOpCallback (splatOp);
347351 return splatOp.getResult ();
348352 }
349- SplatElementsAttr splatAttr;
350- if (matchPattern (input, m_Constant (&splatAttr))) {
351- auto constantOp = arith::ConstantOp::create (
352- builder, targetType,
353- SplatElementsAttr::get (targetType,
354- splatAttr.getSplatValue <TypedAttr>()));
355- createdOpCallback (constantOp);
356- return constantOp.getResult ();
357- }
353+ auto constantOp = arith::ConstantOp::create (
354+ builder, targetType,
355+ SplatElementsAttr::get (targetType,
356+ splatAttr.getSplatValue <TypedAttr>()));
357+ createdOpCallback (constantOp);
358+ return constantOp.getResult ();
358359 }
359360
360361 // If the input is a dense/splat constant, evaluate the relation on its
0 commit comments