Skip to content

Commit f734ceb

Browse files
authored
[LoongArch] Initial implementation for enableMemCmpExpansion hook (llvm#166526)
After overriding `TargetTransformInfo::enableMemCmpExpansion` in this commit, `MergeICmps` and `ExpandMemCmp` passes will be enabled on LoongArch.
1 parent b3d6264 commit f734ceb

File tree

5 files changed

+4255
-1253
lines changed

5 files changed

+4255
-1253
lines changed

llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,25 @@ bool LoongArchTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const {
111111
}
112112
}
113113

114-
// TODO: Implement more hooks to provide TTI machinery for LoongArch.
114+
LoongArchTTIImpl::TTI::MemCmpExpansionOptions
115+
LoongArchTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {
116+
TTI::MemCmpExpansionOptions Options;
117+
118+
if (!ST->hasUAL())
119+
return Options;
120+
121+
Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
122+
Options.NumLoadsPerBlock = Options.MaxNumLoads;
123+
Options.AllowOverlappingLoads = true;
124+
125+
// TODO: Support for vectors.
126+
if (ST->is64Bit()) {
127+
Options.LoadSizes = {8, 4, 2, 1};
128+
Options.AllowedTailExpansions = {3, 5, 6};
129+
} else {
130+
Options.LoadSizes = {4, 2, 1};
131+
Options.AllowedTailExpansions = {3};
132+
}
133+
134+
return Options;
135+
}

llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class LoongArchTTIImpl : public BasicTTIImplBase<LoongArchTTIImpl> {
5555

5656
bool shouldExpandReduction(const IntrinsicInst *II) const override;
5757

58-
// TODO: Implement more hooks to provide TTI machinery for LoongArch.
58+
TTI::MemCmpExpansionOptions
59+
enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const override;
5960
};
6061

6162
} // end namespace llvm

0 commit comments

Comments
 (0)