[Mlir-commits] [mlir] [mlir][tensor] Fix crash when canonicalizing invalid IR (PR #72888)

Mehdi Amini llvmlistbot at llvm.org
Mon Nov 20 16:46:46 PST 2023


================
@@ -256,13 +256,20 @@ std::optional<int64_t> constantTripCount(OpFoldResult lb, OpFoldResult ub,
   return mlir::ceilDiv(*ubConstant - *lbConstant, *stepConstant);
 }
 
-LogicalResult foldDynamicIndexList(SmallVectorImpl<OpFoldResult> &ofrs) {
+LogicalResult foldDynamicIndexList(SmallVectorImpl<OpFoldResult> &ofrs,
+                                   bool onlyNonNegative) {
   bool valuesChanged = false;
   for (OpFoldResult &ofr : ofrs) {
     if (ofr.is<Attribute>())
       continue;
-    Attribute attr;
-    if (matchPattern(ofr.get<Value>(), m_Constant(&attr))) {
+    APInt intVal;
+    if (matchPattern(ofr.get<Value>(), m_ConstantInt(&intVal))) {
+      if (intVal.isNegative() && onlyNonNegative)
+        continue;
+      Attribute attr;
+      bool isConstant = matchPattern(ofr.get<Value>(), m_Constant(&attr));
----------------
joker-eph wrote:

Is this the most efficient way? (knowing that you just matched in the `if` above)

https://github.com/llvm/llvm-project/pull/72888


More information about the Mlir-commits mailing list