Skip to content

Commit

Permalink
[X86] Skip AMX type lowering when AMX is not used (llvm#92910)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aengelke authored Jun 6, 2024
1 parent c0a8fb2 commit ac5e278
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions llvm/lib/Target/X86/X86LowerAMXType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ static bool isAMXIntrinsic(Value *I) {
return false;
}

static bool containsAMXCode(Function &F) {
for (BasicBlock &BB : F)
for (Instruction &I : BB)
if (I.getType()->isX86_AMXTy())
return true;
return false;
}

static AllocaInst *createAllocaInstAtEntry(IRBuilder<> &Builder, BasicBlock *BB,
Type *Ty) {
Function &F = *BB->getParent();
Expand Down Expand Up @@ -1230,6 +1238,14 @@ class X86LowerAMXTypeLegacyPass : public FunctionPass {
}

bool runOnFunction(Function &F) override {
// Performance optimization: most code doesn't use AMX, so return early if
// there are no instructions that produce AMX values. This is sufficient, as
// AMX arguments and constants are not allowed -- so any producer of an AMX
// value must be an instruction.
// TODO: find a cheaper way for this, without looking at all instructions.
if (!containsAMXCode(F))
return false;

bool C = false;
TargetMachine *TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
TargetLibraryInfo *TLI =
Expand Down

0 comments on commit ac5e278

Please sign in to comment.