================
@@ -4439,6 +4448,68 @@ bool ExtVectorElementExpr::containsDuplicateElements()
const {
return false;
}
+/// containsDuplicateElements - Return true if any Matrix element access is
+/// repeated.
+bool MatrixElementExpr::containsDuplicateElements() const {
+ StringRef Comp = Accessor->getName();
+ assert(!Comp.empty() && Comp[0] == '_' && "invalid matrix accessor");
+
+ // Get the matrix type so we know bounds.
+ const ConstantMatrixType *MT =
+ getBase()->getType()->getAs<ConstantMatrixType>();
+ assert(MT && "MatrixElementExpr base must be a matrix type");
+
+ unsigned Rows = MT->getNumRows();
+ unsigned Cols = MT->getNumColumns();
+ unsigned Max = Rows * Cols;
+
+ // Zero-indexed: _mRC (4 chars per component)
+ // One-indexed: _RC (3 chars per component)
+ bool IsZeroIndexed = false;
+ unsigned ChunkLen = 0;
+
+ if (Comp.size() >= 2 && Comp[0] == '_' && Comp[1] == 'm') {
+ IsZeroIndexed = true;
+ ChunkLen = 4;
+ } else {
+ IsZeroIndexed = false;
+ ChunkLen = 3;
+ }
+
+ assert(ChunkLen && "unrecognized matrix swizzle format");
+ assert(Comp.size() % ChunkLen == 0 &&
+ "matrix swizzle accessor has invalid length");
+
+ // Track visited elements using real matrix size.
+ SmallVector<bool, 16> Seen(Max, false);
+
+ for (unsigned I = 0, e = Comp.size(); I < e; I += ChunkLen) {
----------------
hekota wrote:
```suggestion
for (unsigned I = 0, E = Comp.size(); I < E; I += ChunkLen) {
```
https://github.com/llvm/llvm-project/pull/171225
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits