Skip to content

Commit 23936ed

Browse files
committed
Add size and element width requirements to ShiftOp verify for Vectors
1 parent e8dd5e3 commit 23936ed

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "mlir/Interfaces/ControlFlowInterfaces.h"
1919
#include "mlir/Interfaces/FunctionImplementation.h"
20-
#include "mlir/Support/LogicalResult.h"
2120

2221
#include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
2322
#include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
@@ -1427,15 +1426,32 @@ OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
14271426
//===----------------------------------------------------------------------===//
14281427
LogicalResult cir::ShiftOp::verify() {
14291428
mlir::Operation *op = getOperation();
1430-
const bool isOp0Vec = mlir::isa<cir::VectorType>(op->getOperand(0).getType());
1431-
const bool isOp1Vec = mlir::isa<cir::VectorType>(op->getOperand(1).getType());
1432-
if (isOp0Vec != isOp1Vec)
1429+
auto op0VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(0).getType());
1430+
auto op1VecTy = mlir::dyn_cast<cir::VectorType>(op->getOperand(1).getType());
1431+
if (!op0VecTy ^ !op1VecTy)
14331432
return emitOpError() << "input types cannot be one vector and one scalar";
14341433

1435-
if (isOp1Vec && !mlir::isa<cir::VectorType>(getResult().getType())) {
1436-
return emitOpError() << "the type of the result must be a vector "
1437-
<< "if it is vector shift";
1434+
if (op0VecTy) {
1435+
if (op0VecTy.getSize() != op1VecTy.getSize())
1436+
return emitOpError() << "input vector types must have the same size";
1437+
1438+
auto opResultTy = mlir::dyn_cast<cir::VectorType>(getResult().getType());
1439+
if (!opResultTy)
1440+
return emitOpError() << "the type of the result must be a vector "
1441+
<< "if it is vector shift";
1442+
1443+
auto op0VecEleTy = mlir::cast<cir::IntType>(op0VecTy.getElementType());
1444+
auto op1VecEleTy = mlir::cast<cir::IntType>(op1VecTy.getElementType());
1445+
if (op0VecEleTy.getWidth() != op1VecEleTy.getWidth())
1446+
return emitOpError()
1447+
<< "vector operands do not have the same elements sizes";
1448+
1449+
auto resVecEleTy = mlir::cast<cir::IntType>(opResultTy.getElementType());
1450+
if (op0VecEleTy.getWidth() != resVecEleTy.getWidth())
1451+
return emitOpError() << "vector operands and result type do not have the "
1452+
"same elements sizes";
14381453
}
1454+
14391455
return mlir::success();
14401456
}
14411457

0 commit comments

Comments
 (0)