[Mlir-commits] [mlir] [mlir] Guard sccp pass from crashing with different source type (PR #120656)
Kai Sasaki
llvmlistbot at llvm.org
Tue Dec 24 16:48:41 PST 2024
================
@@ -2523,8 +2523,16 @@ OpFoldResult BroadcastOp::fold(FoldAdaptor adaptor) {
if (!adaptor.getSource())
return {};
auto vectorType = getResultVectorType();
- if (llvm::isa<IntegerAttr, FloatAttr>(adaptor.getSource()))
- return DenseElementsAttr::get(vectorType, adaptor.getSource());
+ if (auto attr = llvm::dyn_cast<IntegerAttr>(adaptor.getSource())) {
+ if (vectorType.getElementType() != attr.getType())
+ return {};
+ return DenseElementsAttr::get(vectorType, attr);
+ }
+ if (auto attr = llvm::dyn_cast<FloatAttr>(adaptor.getSource())) {
+ if (vectorType.getElementType() != attr.getType())
+ return {};
+ return DenseElementsAttr::get(vectorType, attr);
+ }
----------------
Lewuathe wrote:
`dyn_cast` cannot take multiple arguments to be casted.
```
if (auto attr = (llvm::dyn_cast<IntegerAttr>(adaptor.getSource()) || llvm::dyn_cast<FloatAttr>(adaptor.getSource()))) {
```
Even if I unioned the result of the cast like this, it causes the following error.
```
llvm-project/mlir/lib/Dialect/Vector/IR/VectorOps.cpp:2527:44: error: member reference base type 'bool' is not a structure or union
if (vectorType.getElementType() != attr.getType())
```
So we can only separate the logic to handle int and float separetely.
https://github.com/llvm/llvm-project/pull/120656
More information about the Mlir-commits
mailing list