Skip to content

Commit ac5e278

Browse files
authored
[X86] Skip AMX type lowering when AMX is not used (#92910)
The pass iterates over the IR multiple times, but most code doesn't use AMX. Therefore, do a single iteration in advance to check whether a function uses AMX at all, and exit early if it doesn't. This makes the function-has-AMX path slightly more expensive, but AMX users probably care a lot less about compile time than JIT users (which tend to not use AMX). For us, it reduces the time spent in this pass from 0.62% to 0.12%. Ideally, we wouldn't even need to iterate over the function to determine that it doesn't use AMX.
1 parent c0a8fb2 commit ac5e278

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

llvm/lib/Target/X86/X86LowerAMXType.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ static bool isAMXIntrinsic(Value *I) {
9292
return false;
9393
}
9494

95+
static bool containsAMXCode(Function &F) {
96+
for (BasicBlock &BB : F)
97+
for (Instruction &I : BB)
98+
if (I.getType()->isX86_AMXTy())
99+
return true;
100+
return false;
101+
}
102+
95103
static AllocaInst *createAllocaInstAtEntry(IRBuilder<> &Builder, BasicBlock *BB,
96104
Type *Ty) {
97105
Function &F = *BB->getParent();
@@ -1230,6 +1238,14 @@ class X86LowerAMXTypeLegacyPass : public FunctionPass {
12301238
}
12311239

12321240
bool runOnFunction(Function &F) override {
1241+
// Performance optimization: most code doesn't use AMX, so return early if
1242+
// there are no instructions that produce AMX values. This is sufficient, as
1243+
// AMX arguments and constants are not allowed -- so any producer of an AMX
1244+
// value must be an instruction.
1245+
// TODO: find a cheaper way for this, without looking at all instructions.
1246+
if (!containsAMXCode(F))
1247+
return false;
1248+
12331249
bool C = false;
12341250
TargetMachine *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
12351251
TargetLibraryInfo *TLI =

0 commit comments

Comments
 (0)