diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp index 53870e414c199..452dade61e328 100644 --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -324,14 +324,11 @@ static LogicalResult verify(AllocLikeOp op) { 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 {