@@ -263,16 +263,17 @@ static void promoteIfBlock(AffineIfOp ifOp, bool elseBlock) {
263263static Operation *getOutermostInvariantForOp (AffineIfOp ifOp) {
264264 // Walk up the parents past all for op that this conditional is invariant on.
265265 auto ifOperands = ifOp.getOperands ();
266- auto *res = ifOp. getOperation () ;
267- while (!isa<func::FuncOp>( res->getParentOp ())) {
266+ Operation *res = ifOp;
267+ while (!res->getParentOp ()-> hasTrait <OpTrait::IsIsolatedFromAbove>( )) {
268268 auto *parentOp = res->getParentOp ();
269269 if (auto forOp = dyn_cast<AffineForOp>(parentOp)) {
270270 if (llvm::is_contained (ifOperands, forOp.getInductionVar ()))
271271 break ;
272272 } else if (auto parallelOp = dyn_cast<AffineParallelOp>(parentOp)) {
273- for (auto iv : parallelOp.getIVs ())
274- if (llvm::is_contained (ifOperands, iv))
275- break ;
273+ if (llvm::any_of (parallelOp.getIVs (), [&](Value iv) {
274+ return llvm::is_contained (ifOperands, iv);
275+ }))
276+ break ;
276277 } else if (!isa<AffineIfOp>(parentOp)) {
277278 // Won't walk up past anything other than affine.for/if ops.
278279 break ;
@@ -438,11 +439,10 @@ LogicalResult mlir::affine::hoistAffineIfOp(AffineIfOp ifOp, bool *folded) {
438439 if (folded)
439440 *folded = false ;
440441
441- // The folding above should have ensured this, but the affine.if's
442- // canonicalization is missing composition of affine.applys into it.
442+ // The folding above should have ensured this.
443443 assert (llvm::all_of (ifOp.getOperands (),
444444 [](Value v) {
445- return isTopLevelValue (v) || isAffineForInductionVar (v);
445+ return isTopLevelValue (v) || isAffineInductionVar (v);
446446 }) &&
447447 " operands not composed" );
448448
0 commit comments