@@ -399,6 +399,18 @@ bubbleUpPackOpThroughGenericOp(RewriterBase &rewriter, tensor::PackOp packOp,
399399 if (!genericOp->getResult (0 ).hasOneUse ())
400400 return failure ();
401401
402+ // TODO: Add an option for allowing padding values. It could introduce
403+ // undefined behavior if we unconditionally propagate pack op through all
404+ // the ops. E.g., if the padding value is zero and there are division ops in
405+ // a generic op. Some values of padding area could be NaN (0/0).
406+ if (packOp.getPaddingValue ())
407+ return failure ();
408+
409+ OpOperand *opOperand = genericOp.getDpsInitOperand (0 );
410+ auto packInfo = getPackingInfoFromOperand (opOperand, genericOp, packOp);
411+ if (failed (packInfo))
412+ return failure ();
413+
402414 // We want to move the pack not the generic.
403415 OpBuilder::InsertionGuard guard (rewriter);
404416 rewriter.setInsertionPoint (genericOp);
@@ -422,18 +434,6 @@ bubbleUpPackOpThroughGenericOp(RewriterBase &rewriter, tensor::PackOp packOp,
422434 return failure ();
423435 }
424436
425- // TODO: Add an option for allowing padding values. It could introduce
426- // undefined behavior if we unconditionally propagate pack op through all
427- // the ops. E.g., if the padding value is zero and there are division ops in
428- // a generic op. Some values of padding area could be NaN (0/0).
429- if (packOp.getPaddingValue ())
430- return failure ();
431-
432- OpOperand *opOperand = genericOp.getDpsInitOperand (0 );
433- auto packInfo = getPackingInfoFromOperand (opOperand, genericOp, packOp);
434- if (failed (packInfo))
435- return failure ();
436-
437437 // Rebuild the indexing map for the corresponding init operand.
438438 auto [packedOutOperand, packedOutIndexingMap] =
439439 getOrCreatePackedViewOfOperand (rewriter, genericOp.getLoc (), *packInfo,
0 commit comments