diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -324,14 +324,11 @@ return success(); // An alloca op needs to have an ancestor with an allocation scope trait. - auto *parentOp = op.getParentOp(); - while (parentOp) { - if (parentOp->template hasTrait()) - return success(); - parentOp = parentOp->getParentOp(); - } - return op.emitOpError( - "requires an ancestor op with AutomaticAllocationScope trait"); + if (!op.template getParentWithTrait()) + return op.emitOpError( + "requires an ancestor op with AutomaticAllocationScope trait"); + + return success(); } namespace {