Skip to content

Commit 8f9aac4

Browse files
[mlir][vector] Fix invalid IR in vector.print lowering (#74410)
`DecomposePrintOpConversion` used to generate invalid op such as: ``` error: 'arith.extsi' op operand type 'vector<10xi32>' and result type 'vector<10xi32>' are cast incompatible vector.print %v9 : vector<10xi32> ``` This commit fixes tests such as `mlir/test/Integration/Dialect/Vector/CPU/test-reductions-i32.mlir` when verifying the IR after each pattern application (#74270).
1 parent 68f91cd commit 8f9aac4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,14 @@ struct DecomposePrintOpConversion : public VectorToSCFPattern<vector::PrintOp> {
726726
auto targetVectorType = vectorType.cloneWith({}, legalIntTy);
727727
value = rewriter.create<vector::BitCastOp>(loc, signlessSourceVectorType,
728728
value);
729-
if (width == 1 || intTy.isUnsigned())
730-
value = rewriter.create<arith::ExtUIOp>(loc, signlessTargetVectorType,
731-
value);
732-
else
733-
value = rewriter.create<arith::ExtSIOp>(loc, signlessTargetVectorType,
734-
value);
729+
if (value.getType() != signlessTargetVectorType) {
730+
if (width == 1 || intTy.isUnsigned())
731+
value = rewriter.create<arith::ExtUIOp>(loc, signlessTargetVectorType,
732+
value);
733+
else
734+
value = rewriter.create<arith::ExtSIOp>(loc, signlessTargetVectorType,
735+
value);
736+
}
735737
value = rewriter.create<vector::BitCastOp>(loc, targetVectorType, value);
736738
vectorType = targetVectorType;
737739
}

0 commit comments

Comments
 (0)