Skip to content

Commit c7961b6

Browse files
Merge pull request #3193 from belfortlabs:mdgrs/avoidDenseLayoutCheck
PiperOrigin-RevId: 947979601
2 parents 09065c2 + a8e4189 commit c7961b6

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

lib/Transforms/ConvertToCiphertextSemantics/AssignLayout.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)