@@ -1044,9 +1044,8 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
10441044 assert (op.getType () == op.getInput ().getType () &&
10451045 " Unary operation's operand type and result type are different" );
10461046 mlir::Type type = op.getType ();
1047- mlir::Type elementType = type;
1048- bool isVector = false ;
1049- assert (!cir::MissingFeatures::vectorType ());
1047+ mlir::Type elementType = elementTypeIfVector (type);
1048+ bool isVector = mlir::isa<cir::VectorType>(type);
10501049 mlir::Type llvmType = getTypeConverter ()->convertType (type);
10511050 mlir::Location loc = op.getLoc ();
10521051
@@ -1076,20 +1075,30 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
10761075 rewriter.replaceOp (op, adaptor.getInput ());
10771076 return mlir::success ();
10781077 case cir::UnaryOpKind::Minus: {
1079- assert (!isVector &&
1080- " Add vector handling when vector types are supported" );
1081- mlir::LLVM::ConstantOp zero = rewriter.create <mlir::LLVM::ConstantOp>(
1082- loc, llvmType, mlir::IntegerAttr::get (llvmType, 0 ));
1078+ mlir::Value zero;
1079+ if (isVector)
1080+ zero = rewriter.create <mlir::LLVM::ZeroOp>(loc, llvmType);
1081+ else
1082+ zero = rewriter.create <mlir::LLVM::ConstantOp>(
1083+ loc, llvmType, mlir::IntegerAttr::get (llvmType, 0 ));
10831084 rewriter.replaceOpWithNewOp <mlir::LLVM::SubOp>(
10841085 op, llvmType, zero, adaptor.getInput (), maybeNSW);
10851086 return mlir::success ();
10861087 }
10871088 case cir::UnaryOpKind::Not: {
10881089 // bit-wise compliment operator, implemented as an XOR with -1.
1089- assert (!isVector &&
1090- " Add vector handling when vector types are supported" );
1091- mlir::LLVM::ConstantOp minusOne = rewriter.create <mlir::LLVM::ConstantOp>(
1092- loc, llvmType, mlir::IntegerAttr::get (llvmType, -1 ));
1090+ mlir::Value minusOne;
1091+ if (isVector) {
1092+ const uint64_t numElements =
1093+ mlir::dyn_cast<cir::VectorType>(type).getSize ();
1094+ std::vector<int32_t > values (numElements, -1 );
1095+ mlir::DenseIntElementsAttr denseVec = rewriter.getI32VectorAttr (values);
1096+ minusOne =
1097+ rewriter.create <mlir::LLVM::ConstantOp>(loc, llvmType, denseVec);
1098+ } else {
1099+ minusOne = rewriter.create <mlir::LLVM::ConstantOp>(
1100+ loc, llvmType, mlir::IntegerAttr::get (llvmType, -1 ));
1101+ }
10931102 rewriter.replaceOpWithNewOp <mlir::LLVM::XOrOp>(
10941103 op, llvmType, adaptor.getInput (), minusOne);
10951104 return mlir::success ();
0 commit comments