<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117119>117119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][TensorOps][Canonicalize][FoldDimOfExpandShape]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hockyy
</td>
</tr>
</table>
<pre>
https://github.com/llvm/llvm-project/blame/476b208e0115e766605e9f850982996a1d51c287/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp#L1988
@matthias-springer
Why the assert?
```
// `dim` is the only dynamic dimension in `group`. (Otherwise, the
// ExpandShapeOp would be ambiguous.)
int64_t product = 1;
ReassociationIndices grp = expandShapeOp.getReassociationIndices()[srcDim];
bool multiDynamicDim = false;
for (int64_t d : grp) {
if (d != dim) {
if (resultType.isDynamicDim(d)) {
multiDynamicDim = true;
break;
}
// assert(!resultType.isDynamicDim(d) && "expected static dim");
product *= resultType.getDimSize(d);
}
}
LLVM_DEBUG(llvm::dbgs() << expandShapeOp << "\n";);
int dynIndex = 0;
for (int i = 0; i < *dim; i++) {
if (ShapedType::isDynamic(expandShapeOp.getStaticOutputShape()[i]))
dynIndex++;
}
for (auto tmp : expandShapeOp.getOutputShape()) {
LLVM_DEBUG(llvm::dbgs() << tmp << "\n";);
}
for (auto tmp : expandShapeOp.getStaticOutputShape()) {
LLVM_DEBUG(llvm::dbgs() << tmp << "\n";);
}
if (multiDynamicDim) {
rewriter.replaceOp(dimOp, expandShapeOp.getOutputShape()[dynIndex]);
return success();
}
```
can we do this for better handling?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk2PozgT_jXOxZrIlAOEQw5JGF611K8iTc_uHkcGV4N3ACPbTHf2169s8kWne3fmsBGC2NTHU_U8UAhrVd0jbki8I3G-EKNrtNk0uvp-PC5KLY-bxrnBEr4lUBAoauWasVxWui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