Skip to content

Commit 69a2a27

Browse files
AmrDeveloperlanza
authored andcommitted
[CIR] Backport add mlir Vec to elementTypeIfVector (llvm#1622)
Add mlir Vec support to elementTypeIfVector
1 parent 3eb6f01 commit 69a2a27

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ mlir::LLVM::FCmpPredicate convertCmpKindToFCmpPredicate(cir::CmpOpKind kind) {
138138
/// If the given type is a vector type, return the vector's element type.
139139
/// Otherwise return the given type unchanged.
140140
mlir::Type elementTypeIfVector(mlir::Type type) {
141-
if (auto VecType = mlir::dyn_cast<cir::VectorType>(type)) {
142-
return VecType.getElementType();
143-
}
144-
return type;
141+
return llvm::TypeSwitch<mlir::Type, mlir::Type>(type)
142+
.Case<cir::VectorType, mlir::VectorType>(
143+
[](auto p) { return p.getElementType(); })
144+
.Default([](mlir::Type p) { return p; });
145145
}
146146

147147
mlir::LLVM::Visibility
@@ -2763,13 +2763,10 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
27632763
cir::VectorType, mlir::IntegerType>(type)) &&
27642764
"operand type not supported yet");
27652765

2766-
auto llvmTy = getTypeConverter()->convertType(op.getType());
2767-
mlir::Type llvmEltTy =
2768-
mlir::isa<mlir::VectorType>(llvmTy)
2769-
? mlir::cast<mlir::VectorType>(llvmTy).getElementType()
2770-
: llvmTy;
2771-
auto rhs = adaptor.getRhs();
2772-
auto lhs = adaptor.getLhs();
2766+
mlir::Type llvmTy = getTypeConverter()->convertType(op.getType());
2767+
mlir::Type llvmEltTy = elementTypeIfVector(llvmTy);
2768+
mlir::Value rhs = adaptor.getRhs();
2769+
mlir::Value lhs = adaptor.getLhs();
27732770

27742771
type = elementTypeIfVector(type);
27752772

0 commit comments

Comments
 (0)