Skip to content

Commit 9308ba1

Browse files
committed
fix(t2l): handle detached normalized mask bases
Stop relying on the parent operation of a block argument while dialect conversion may detach its owner block. Carry the exact i1-to-i8 normalization classification from base resolution and initialize BlockData directly from the verified memref<?xi8> remap, while preserving the existing parser for ordinary adaptor bases.
1 parent ad4a3b0 commit 9308ba1

1 file changed

Lines changed: 30 additions & 12 deletions

File tree

third_party/ascend/lib/TritonToLinalg/BlockPtrAnalysis.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,19 +1660,27 @@ memref::ReinterpretCastOp createRedundantOp(triton::MakeTensorPtrOp op,
16601660
return castOp;
16611661
}
16621662

1663-
static FailureOr<Value>
1663+
// Carries the converted runtime descriptor and records whether the resolver
1664+
// has already proven the complete ptr<i1>-to-ptr<i8> normalization contract.
1665+
// That exact fallback can initialize BlockData without consulting conversion
1666+
// state attached to the original bitcast result.
1667+
struct ResolvedMakeTensorPtrBase {
1668+
Value value;
1669+
bool normalizedI1ToI8 = false;
1670+
};
1671+
1672+
static FailureOr<ResolvedMakeTensorPtrBase>
16641673
resolveMakeTensorPtrBase(triton::MakeTensorPtrOp op, Value adaptorBase,
16651674
ConversionPatternRewriter &rewriter) {
16661675
if (adaptorBase && isa<BaseMemRefType>(adaptorBase.getType()))
1667-
return adaptorBase;
1676+
return ResolvedMakeTensorPtrBase{adaptorBase};
16681677

16691678
auto bitcast = op.getBase().getDefiningOp<triton::BitcastOp>();
16701679
if (!bitcast)
16711680
return failure();
16721681

16731682
auto sourceArgument = dyn_cast<BlockArgument>(bitcast.getSrc());
1674-
if (!sourceArgument ||
1675-
!isa<triton::FuncOp>(sourceArgument.getOwner()->getParentOp()))
1683+
if (!sourceArgument)
16761684
return failure();
16771685

16781686
auto sourcePointer =
@@ -1693,28 +1701,38 @@ resolveMakeTensorPtrBase(triton::MakeTensorPtrOp op, Value adaptorBase,
16931701
if (!sourceMemRef || sourceMemRef != expectedType)
16941702
return failure();
16951703

1696-
return convertedSource;
1704+
return ResolvedMakeTensorPtrBase{convertedSource,
1705+
/*normalizedI1ToI8=*/true};
16971706
}
16981707

16991708
LogicalResult BlockDataParser::rewriteMakeTensorPtrOp(
17001709
triton::MakeTensorPtrOp op, Value convertedBase,
17011710
ConversionPatternRewriter &rewriter,
17021711
llvm::SmallDenseMap<Value, BlockData> &known) {
1703-
FailureOr<Value> resolvedBase =
1712+
FailureOr<ResolvedMakeTensorPtrBase> resolvedBase =
17041713
resolveMakeTensorPtrBase(op, convertedBase, rewriter);
17051714
if (failed(resolvedBase)) {
17061715
op.emitOpError("expected the converted base to be a memref descriptor");
17071716
return failure();
17081717
}
1709-
convertedBase = *resolvedBase;
1718+
convertedBase = resolvedBase->value;
17101719
Location loc = op.getLoc();
17111720
BlockData data;
17121721

1713-
// Parse the original producer only for semantic information such as a
1714-
// bitcast element type. The runtime source always comes from the resolved
1715-
// converted base so SCF-selected memref descriptors are not bypassed.
1716-
if (failed(BlockDataParser::parse(op.getBase(), data, loc, rewriter, known)))
1717-
return failure();
1722+
if (resolvedBase->normalizedI1ToI8) {
1723+
// The resolver has already established the complete normalized mask-base
1724+
// contract. Avoid querying the bitcast result mapping while dialect
1725+
// conversion may still be rewriting its owner block.
1726+
data.setSource(convertedBase);
1727+
data.setResElemTy(rewriter.getIntegerType(8));
1728+
} else {
1729+
// Parse the original producer only for semantic information such as a
1730+
// bitcast element type. The runtime source always comes from the resolved
1731+
// converted base so SCF-selected memref descriptors are not bypassed.
1732+
if (failed(
1733+
BlockDataParser::parse(op.getBase(), data, loc, rewriter, known)))
1734+
return failure();
1735+
}
17181736
if (!data.hasSource()) {
17191737
op.emitOpError("failed to resolve the converted scalar base");
17201738
return failure();

0 commit comments

Comments
 (0)